In gdb stepping, you can change the value of a variable by running:
(gdb) set myvar=5
to change the variable myvar to 5.
Because an std::string is not a primitive data type, it cannot be changed in this way.
The std::string is a class and it has methods that you can call in gdb to change the value of an instance of it. For example, if mystring is an object of std::string, you can do either:
(gdb) call mystring.assign("new value")
or
(gdb) call mystring.operator=("new value")
to change the value of mystring into "new value".
Showing posts with label gdb. Show all posts
Showing posts with label gdb. Show all posts
Saturday, April 13, 2013
Wednesday, November 10, 2010
Crash, core dump and gdb
When a linux program crashes, a core file could be generated under the directory where you ran the file. A core file contains very useful information to help you debug the program. If there is no such a file named core.XXXX, it may be that the parameter of the maximum size of core files is set as 0. Check it with this command:
$ ulimit -c
If the result is 0, set a size for it, e.g.
$ ulimit -c 100000
If the core file is generated, you can run gdb to exam the core file and see why and where the crash happened.
$ gdb /path/to/your/program core.XXXX
If your source code is somewhere else, include the location of the source code in the gdb command line.
$ gdb -d /path/to/source-code /path/to/program core.XXXX
It brings you to the crash location in your source code. If you want to see a back trace, run the gdb command bt.
(gdb) bt
$ ulimit -c
If the result is 0, set a size for it, e.g.
$ ulimit -c 100000
If the core file is generated, you can run gdb to exam the core file and see why and where the crash happened.
$ gdb /path/to/your/program core.XXXX
If your source code is somewhere else, include the location of the source code in the gdb command line.
$ gdb -d /path/to/source-code /path/to/program core.XXXX
It brings you to the crash location in your source code. If you want to see a back trace, run the gdb command bt.
(gdb) bt
Wednesday, June 16, 2010
gdb: skip instructions or lines while stepping the program
Supposed you are at line 50 and you want to skip the following several lines of your source code and continue from line 60, you can input command
jump 60
However, the command will continue your program till it meets next break point or the end of the program. So before you run the "jump" command, you should set a break point first.
break 60
jump 60
You can issue the command in its short form.
b 60
j 60
Alternatively, if the line you want to skip is a function call, you can step into it first, and return right after.
s
return
You would need to mind the return value if the function returns something.
jump 60
However, the command will continue your program till it meets next break point or the end of the program. So before you run the "jump" command, you should set a break point first.
break 60
jump 60
You can issue the command in its short form.
b 60
j 60
Alternatively, if the line you want to skip is a function call, you can step into it first, and return right after.
s
return
You would need to mind the return value if the function returns something.
Subscribe to:
Posts (Atom)