Consider the following code:
#include <stdio.h>
#include <ctype.h>
char* Mstrupr(char* szCad);
int main()
{
char szCadena[] = "This string should print well.";
printf("%s\n", Mstrupr(szCadena));
printf("%s\n", Mstrupr("This string should fail."));
return 0;
}
char* Mstrupr(char* szCad)
{
int i;
for (i=0; szCad[i]; i++)
szCad[i] = toupper(szCad[i]);
return szCad;
}
The second call to Mstrupr fails to run correctly on linux as its receiving the string as a literal (and not as a char array). When the complete program is run on gdb it fails as well, but when a breakpoint is added to main and the program is run via gdb's next command, the second string is capitalized and printed. Why? I believe this should not be, but my instructor insists that it's part of gdb's design.
To stop your program while it is running, type "(ctrl) + c" (hold down the ctrl key and press c). gdb will stop your program at whatever line it has just executed. From here you can examine variables and move through your program. To specify other places where gdb should stop, see the section on breakpoints below.
A breakpoint makes your program stop whenever a certain point in the program is reached. For each breakpoint, you can add conditions to control in finer detail whether your program stops.
You can see these breakpoints with the GDB maintenance command `maint info breakpoints' . Using the same format as `info breakpoints' , display both the breakpoints you've set explicitly, and those GDB is using for internal purposes. Internal breakpoints are shown with negative breakpoint numbers.
You can use a watchpoint to stop execution whenever the value of an expression changes, without having to predict a particular place where this may happen. (This is sometimes called a data breakpoint.)
I dont see that its part of gdb's design. It seems like an accidental side effect; gdb made the code segment writable when it set the breakpoint, so your code that overwrites literals there now works
In fact no debugger designer would deliberately make their debugger change the behavior of a program; that makes debugging really hard
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With