
I have a multi-threaded program that has just SEGV'd. I want to extract a chunk of data from the program to run in a test program to try and reproduce the problem. Is there a way of telling gdb to dump a chunk of data to a file? The data in question is a regular C string. I tried using p fopen() but it seems that you can't do that sort of thing in a multi-threaded program. p open() fails and I can't work out why. -- My Main Blog http://etbe.coker.com.au/ My Documents Blog http://doc.coker.com.au/

On Mon, 2012-07-23 at 23:26 +1000, Russell Coker wrote:
I have a multi-threaded program that has just SEGV'd. I want to extract a chunk of data from the program to run in a test program to try and reproduce the problem.
Is there a way of telling gdb to dump a chunk of data to a file?
The data in question is a regular C string. I tried using p fopen() but it seems that you can't do that sort of thing in a multi-threaded program. p open() fails and I can't work out why.
(gdb) help set logging Set logging options List of set logging subcommands: set logging file -- Set the current logfile set logging off -- Disable logging set logging on -- Enable logging set logging overwrite -- Set whether logging overwrites or appends to the log file set logging redirect -- Set the logging output mode (gdb) set logging file junk.gdb (gdb) set logging on Copying output to junk.gdb. (gdb) print "1234" $1 = "1234" (gdb) q $ cat junk.gdb $1 = "1234" See also help dump in gdb Current gdb can also use python to examine internal state

On Mon, 23 Jul 2012, Rodney Brown <rdbrown@pacific.net.au> wrote:
(gdb) help set logging Set logging options
List of set logging subcommands:
set logging file -- Set the current logfile
Thanks for that suggestion, I'm currently playing with script(1) which does much the same thing. On Tue, 24 Jul 2012, Andrew Worsley <amworsley@gmail.com> wrote:
Try this link - https://developer.apple.com/library/mac/#documentation/developertools/gdb/g db/gdb_toc.html
In particular try the dump from memory to a file section: https://developer.apple.com/library/mac/#documentation/developertools/gdb/g db/gdb_9.html#SEC75
That's another good option. My initial problem was that I had an open gdb session and the core file which gdb created didn't seem to have the correct data. I've since closed that session and I'm working from kernel generated core files which seems to be more reliable. Thanks for the suggestions. -- My Main Blog http://etbe.coker.com.au/ My Documents Blog http://doc.coker.com.au/

On 23.07.12 23:26, Russell Coker wrote:
I have a multi-threaded program that has just SEGV'd. I want to extract a chunk of data from the program to run in a test program to try and reproduce the problem.
Is there a way of telling gdb to dump a chunk of data to a file?
The data in question is a regular C string. I tried using p fopen() but it seems that you can't do that sort of thing in a multi-threaded program. p open() fails and I can't work out why.
It normally should be possible to print the contents of C variables by name, without manually working out where they are, but the multiple characters of a string might need "x <addr>/17b, if there are 17 characters. I don't remember the neatest way to dump strings, sorry. Here is an excerpt of my notes from using gdb with embedded targets over the years: (gdb) print EXPR # EXPR = Any source language constant, variable or operator. # Includes conditional expressions, function calls, # casts, and string constants. Special EXPR syntax: # FILE::VARIABLE # FUNCTION::VARIABLE (gdb) help print # Gives a bit of info, but nothing on strings. Or Examine memory: (gdb) x 0x8000cc # Examine avr I/O register 0xcc 0x8000cc: 0x22 # xb does same. x/8xw = display 8 hex words. (gdb) set *0x8000cc=0x11 # Setting memory. (gdb) xb 0x8000cc 0x8000cc: 0x11 (gdb) show register # Show cpu register contents. (gdb) disassemble 0x00010003 # Disassemble code. If it doesn't work for you, I'll try it out on a bit of native C, to check what still works for me now, but it's midnight, and I've neglected the fire in the wood heater at this stage. I never did come across any comprehensive gdb documentation, so have just made do with fragments stitched together. Erik -- manual, n.: A unit of documentation. There are always three or more on a given item. One is on the shelf; someone has the others. The information you need is in the others. - Ray Simard

On 24 July 2012 00:07, Erik Christiansen <dvalin@internode.on.net> wrote:
On 23.07.12 23:26, Russell Coker wrote:
I have a multi-threaded program that has just SEGV'd. I want to extract a chunk of data from the program to run in a test program to try and reproduce the problem. .....
Try this link - https://developer.apple.com/library/mac/#documentation/developertools/gdb/gd... In particular try the dump from memory to a file section: https://developer.apple.com/library/mac/#documentation/developertools/gdb/gd...
I never did come across any comprehensive gdb documentation, so have just made do with fragments stitched together.
.... I agree that it's hard to find - but this apple site I found very helpful. Also the reference card is useful to quickly dig out that odd command you haven't used in a few years. http://www.google.com/url?sa=t&rct=j&q=&esrc=s&source=web&cd=1&ved=0CGUQFjAA... Sorry for the google tangled reference - not sure how to unwrap it. I think Apple use a few open source products and in turn provide support. e.g. cups and gdb documentation Andrew

On 24.07.12 07:03, Andrew Worsley wrote:
Try this link - https://developer.apple.com/library/mac/#documentation/developertools/gdb/gd...
In particular try the dump from memory to a file section: https://developer.apple.com/library/mac/#documentation/developertools/gdb/gd...
Many thanks for that. I've linked that into my on-line brain. It makes very fine leisure reading. ...
Also the reference card is useful to quickly dig out that odd command you haven't used in a few years.
http://www.google.com/url?sa=t&rct=j&q=&esrc=s&source=web&cd=1&ved=0CGUQFjAA...
Sorry for the google tangled reference - not sure how to unwrap it.
No drama at all. While highlighting it in mutt did include inter-line whitespace, hitting 'e' to open your post in vim gave a single contiguous string, ready to paste into firefox. Even the reference card contains some stuff I didn't know. (It's amazing how far you can get with just a subset of a tool's instructions.) Thanks again. Erik -- Oregano, n.: The ancient Italian art of pizza folding.
participants (4)
-
Andrew Worsley
-
Erik Christiansen
-
Rodney Brown
-
Russell Coker