You are not logged in.

#1 2011-04-27 08:45:32

realfirst
Member
From: Nanjing, Jiangsu, China
Registered: 2010-05-24
Posts: 4

gdb print command can not show the string literally

Hi all,

i use the gdb to debug a simple C program and encounter a problem as blow.

this is the source i have wrote.

int funca(void) {
  char sa[] = "Hello, funca";
  char *da = 0;
  da = GetNextWord(sa);
  printf (DEBUGFMT "sa=%s da=%s\n", DEBUGARGS, sa, da);
  return 0;
}

and i compile it with the command :

cc -g -Wall main.c funca.c -o main

then i use the gdb --annotate=3 main command to run gdb

and set breakpoint with the command

b funca

and start run with the command r

then use p sa to check the variable

but the result is

(gdb) p sa
$1 = "\000\000\000\000\000\000\000\000\265\a@\000\000"

i use the show charset command to check the charset encoding of my gdb

the result is :
(gdb) show charset
The host character set is "auto; currently UTF-8".
The target character set is "auto; currently UTF-8".
The target wide character set is "auto; currently UTF-32".

have anyone encounter the same problem and have some solution to

deal with it. hope someone can give me an advice and thanks in advance.

Last edited by realfirst (2011-04-27 08:47:08)

Offline

#2 2011-04-27 08:55:15

ber_t
Member
From: Berlin, Germany
Registered: 2010-03-10
Posts: 214
Website

Re: gdb print command can not show the string literally

The variable sa is not initialized at the start of funca(). Use the `step' command to run the next statement, which assigns the address of the "Hello, funca" char array to sa. Using `p sa' afterwards should give the expected result.

Offline

#3 2011-04-27 09:08:05

realfirst
Member
From: Nanjing, Jiangsu, China
Registered: 2010-05-24
Posts: 4

Re: gdb print command can not show the string literally

thank you ber_t for you immediately reply.

i have done as you said and get the right result.

Offline

Board footer

Powered by FluxBB