This is an archive of the discontinued LLVM Phabricator instance.

[lldb] ASan malloc/free history threads
ClosedPublic

Authored by kubamracek on Jul 18 2014, 9:32 PM.

Details

Reviewers
kubamracek
Summary

Hi,
I'm sending a patch that is a first take on implementing the ASan debugging facilities into LLDB, namely retrieving malloc/free recorded stack traces for a given address. This has been somewhat discussed in http://lists.cs.uiuc.edu/pipermail/lldb-dev/2014-July/004491.html. What this patch does is:

  • Creates a new plugin type, MemoryHistory, and its implementation, MemoryHistoryASan. The reason for a plugin is that we might want to reuse it for other sources of recorded stack frames, like malloc_history (Darwin only).
  • The plugin can only be instantiated for a process that has the ASan runtime library loaded. Right now, I'm detecting the presence of the library by checking that a specific symbol exists. Is there a better way?
  • Extended the "memory" command and added "memory history [address]" which will call the plugin's GetHistoryThreads function and print out the HistoryThread objects.
  • A test case that uses a simple ASanified binary and issues the "memory history" command, validates that the returned stack trace contains the correct line number of where a memory was allocated and freed. The test case requires your compiler to understand -fsanitize=address and basically it should be a very recently build clang (so it has the debugging API from this week).

There's a couple of things that I still need to do. I haven't yet exposed this to the SB API, because the patch is already getting quite big. The instance of MemoryHistory should probably be tied to the Process object (same way LanguageRuntime is), so it doesn't get created for every command.

Diff Detail

Event Timeline

kubamracek updated this revision to Diff 11684.Jul 18 2014, 9:32 PM
kubamracek retitled this revision from to [lldb] ASan malloc/free history threads.
kubamracek updated this object.
kubamracek edited the test plan for this revision. (Show Details)
kubamracek added a subscriber: Unknown Object (MLST).
kubamracek updated this revision to Diff 11726.Jul 21 2014, 3:50 PM

Changed the plugin name. Added a method into lldbtest.py that tries to locate Clang in the llvm-build directory, which is needed if your system compiler doesn't have ASan or it doesn't have the recent ASan debugging API.

kubamracek updated this revision to Diff 13188.Sep 2 2014, 7:33 PM

Replaced the "MemoryHistory*" to use MemoryHistorySP instead. Also changed the behavior of the lldbtest.py method for finding the just-built clang to return the path, instead of setting os.environ["CC"], because the environment variable affects subsequent tests.

Looks good Kuba, please commit.

J

kubamracek accepted this revision.Sep 3 2014, 6:14 PM
kubamracek added a reviewer: kubamracek.

Landed in r217116.

This revision is now accepted and ready to land.Sep 3 2014, 6:14 PM
kubamracek closed this revision.Sep 3 2014, 6:14 PM