I am trying to execute printf
function, which is printf ("%*s%s", indent, "", *w)
I know how it works, but I couldn't get the right result, which is "true".
This is what I display the variables in gdb
.
After line 31, I execute:
(gdb) n
and I expected "true" to be printed. Instead, I got nothing as you can see. Why is it behaving like this?
31 printf ("%*s%s", indent, "", *w);
6: **w = 116 't'
5: *w = 0x7ffffffd7eb0 "true"
4: w = (char **) 0x7ffffffd76b0
3: **(c->u.word) = 116 't'
2: *(c->u.word) = 0x7ffffffd7eb0 "true"
1: c->u.word = (char **) 0x7ffffffd76b0
(gdb) n
32 while (*++w) // if next character is not null, keep printing.
6: **w = 116 't'
5: *w = 0x7ffffffd7eb0 "true"
4: w = (char **) 0x7ffffffd76b0
3: **(c->u.word) = 116 't'
2: *(c->u.word) = 0x7ffffffd7eb0 "true"
1: c->u.word = (char **) 0x7ffffffd76b0
After I execute (gdb) n
I expected the value of *w
get printed out. However I got nothing.
Why is it?
Code
case SIMPLE_COMMAND:
{
char **w = c->u.word;
printf ("%*s%s", indent, "", *w);
printf ("%*s%s", indent, "", "true");
while (*++w) // if next character is not null, keep printing.
printf (" %s", *w);
break;
}
The structure of c->u.word looks like this:
struct command
{
int status;
union
{
struct command *command[2];
char **word;
struct command *subshell_command;
} u;
};
EDIT:Another issue detedted
printf ("%*s%s", indent, "", "true");
//abort();
while (*++w) // if next character is not null, keep printing.
printf (" %s", *w);
When I put abort(); after the printf function, it prints out the right output. However, when I decomment abort, it does not print out anything. Also, the line after printf function "while(*++w) causes infinite loop, and I believe that the condition evaluates *++w, and I think it evaluates ++w first and * next.
w = w+1; *w;
How do I get out of this loop?