Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to have LLDB print the locations of shared libraries in memory?

I am trying to gather as much information as I can about an apparent infinite loop issue seen when using Valgrind 3.11.0 on Mac OS 10.11.1 'El Capitan'.

When I run valgrind on my program in LLDB or attach to valgrind running my program and then stop the process, I get a backtrace like the following:

* thread #1: tid = 0x24ab4, 0x000000010805920b, stop reason = signal SIGSTOP
  * frame #0: 0x000000010805920b
    frame #1: 0x0000000108040dda
    frame #2: 0x00000001080b6790
    frame #3: 0x00000001080b2fd3
    frame #4: 0x00000001080b7c25
    frame #5: 0x00000001080b6113
    frame #6: 0x00000001080b3cd0
    frame #7: 0x00000001080c54d9

How do I tell which object(s) these frames correspond to?

I tried vmmap on the process, but it's not showing any information. In particular, the "Non-writable regions for process" section which would normally show the address ranges where the dylibs were mapped into the process' memory is blank:

$ vmmap -v 21729
Process:         memcheck-amd64-darwin [21729]
Path:            /usr/local/Cellar/valgrind/3.11.0/lib/valgrind/memcheck-amd64-darwin
Load Address:    0x100000000
Identifier:      memcheck-amd64-darwin
Version:         ???
Code Type:       X86-64
Parent Process:  bash [11895]

Date/Time:       2015-11-30 11:52:16.392 -0500
Launch Time:     2015-11-30 11:51:53.557 -0500
OS Version:      Mac OS X 10.11.1 (15B42)
Report Version:  7
Analysis Tool:   /Applications/Xcode.app/Contents/Developer/usr/bin/vmmap
Analysis Tool Version:  Xcode 7.1.1 (7B1005)
----

Virtual Memory Map of process 21729 (memcheck-amd64-darwin)
Output report format:  2.4  -- 64-bit process
VM page size:  4096 bytes

==== Non-writable regions for process 21729
REGION TYPE                      START - END             [ VSIZE  RSDNT  DIRTY   SWAP] PRT/MAX SHRMOD PURGE    REGION DETAIL

==== Writable regions for process 21729
REGION TYPE                      START - END             [ VSIZE  RSDNT  DIRTY   SWAP] PRT/MAX SHRMOD PURGE    REGION DETAIL

==== Legend
SM=sharing mode:  
    COW=copy_on_write PRV=private NUL=empty ALI=aliased 
    SHM=shared ZER=zero_filled S/A=shared_alias
PURGE=purgeable mode:  
    V=volatile N=nonvolatile E=empty   otherwise is unpurgeable

==== Summary for process 21729
(null)
like image 947
Daniel Trebbien Avatar asked Nov 30 '15 17:11

Daniel Trebbien


1 Answers

It has been a long time since I used valgrind, I totally forgot how debugging worked with it...

To debug a program that is running under valgrind, you have to tell valgrind to open a gdbserver port for the debugger to talk to. Valgrind knows how to undo all it's magic, and pretend that the program it is managing is just an ordinary program...

That's described in Section 3.2 in:

http://valgrind.org/docs/manual/manual-core-adv.html.

LLDB also knows how to talk using the gdb remote protocol, and has a command gdb-remote to connect to the server.

This doesn't work with lldb straight out of the box, it appears there's some issue with the register definitions. It looks like there's some work on valgrind to improve this:

https://bugs.kde.org/show_bug.cgi?id=356174

But anyway, that's how it is supposed to work.

like image 69
Jim Ingham Avatar answered Nov 01 '22 05:11

Jim Ingham