3

I have a process coredump on a line like

// ptr is boost::shared_ptr<Whatever>
assert(ptr.unique())

That is there are two shared_ptr referencing same object, but program logically expects exclusive ownership. It's logic problem, not memory corruption.

Using gdb I can see address (e.g. 0x001234567890) of pointer, contained in ptr and verify that it's use_count == 2.

Using hexdump on something like it I can easily find other occurrences:

$ xxd core2 | fgrep '9078 5634 1200'
114e3e1e0109c 002c 307f 0000 9078 5634 1200 0000  ...
15b8b2ba000d7 ffa2 307f 0000 9078 5634 1200 0000  ...
1618b644000e7 7fa3 307f 0000 9078 5634 1200 0000  ...

There is a command find in gdb than can search specified region for specified value, but it need correct allocated memory region.

There is a command info mem which shows info about memory regions, but it doesn't work for coredumps.

Are there other ways to find, where this address/value is stored?

2 Answers 2

0

To find the pointers pointing at a piece of memory, you can use valgrind and gdb together.

Then from gdb, you can use the monitor command

(gdb)  monitor who_points_at <addr> [<len>]

to find where are these pointers.

So, if you have 2 references to a piece of memory, who_points_at should be able to return them.

Note that who_points_at is searching for any 'word aligned' data that points at the range [addr, addr + len( So, you might find more occurences as e.g. an integer might 'look' like it is pointing at this memory.

See http://www.valgrind.org/docs/manual/manual-core-adv.html#manual-core-adv.gdbserver and http://www.valgrind.org/docs/manual/mc-manual.html#mc-manual.monitor-commands

for more info.

Sign up to request clarification or add additional context in comments.

1 Comment

not a real solution when debugging core dumps. There is nothing to monitor. "monitor" command not supported by this target.
0

You should consider using valgrind or some address sanitizer (e.g. compile with -fsanitize=address instrumentation option to GCC). It probably is the easiest way to help finding your bug (assuming your bug is reproducible).

Regarding your original question, recent GDB are extendable in Python (and perhaps in Guile). You might write a script for your needs.

You could also put a watchpoint on the use_count field of your smart pointer or pointed object (you may need to disable ASLR to ease debugging).

1 Comment

Sorry for misguidance, but it's not a memory problem. It seems everything GDB provides for python available in plain GDB so it's not an answer. Watchpoint may solve the problem, but there are many dynamically created pointers in runtime and problem arise very seldom.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.