This is the mail archive of the gdb-prs@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug gdb/20981] New: Dynamic library debugging on MacOS X 10.12 (Sierra) and dyld 15 is broken


https://sourceware.org/bugzilla/show_bug.cgi?id=20981

            Bug ID: 20981
           Summary: Dynamic library debugging on MacOS X 10.12 (Sierra)
                    and dyld 15 is broken
           Product: gdb
           Version: HEAD
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: gdb
          Assignee: unassigned at sourceware dot org
          Reporter: stefan.mb at gmail dot com
  Target Milestone: ---

I am running Mac OS X 10.12.2 (Sierra) and I've noticed gdb's support for
debugging dynamic libraries is broken. The following message is printed on
startup:

"warning: unhandled dyld version (15)"

It appears the latest dyld on MacOS Sierra has undergone major changes and the
version was bumped from 14 to 15.
(https://opensource.apple.com/source/dyld/dyld-421.2/) 

Last time a version bump happened the fix was to simply modify the
DYLD_VERSION_MAX define (see
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;a=commit;h=d4ccb5e05c99c4006fe43ab08ebe13b7a74fc111).

I tried doing this and was met with a new error:

"Cannot insert breakpoint -1
Cannot access memory at address 0xe85d"

The address 0xe85d is the offset of the "gdb_image_notifier" function in the
/usr/lib/dyld executable (see
https://opensource.apple.com/source/dyld/dyld-421.2/src/dyld_gdb.cpp.auto.html).

It appears Apple has changed something fundamental about how dyld is built
and/or loaded (possibly related to PIE/ASLR), here are before and after
examples:

Mac OS X 10.11.6:

otool -l /usr/lib/dyld 
Mach header
      magic cputype cpusubtype  caps    filetype ncmds sizeofcmds      flags
 0xfeedfacf 16777223          3  0x00           7    14       1696 0x00000085
Load command 0
      cmd LC_SEGMENT_64
  cmdsize 552
  segname __TEXT
   vmaddr 0x00007fff5fc00000
   vmsize 0x0000000000038000
  fileoff 0
 filesize 229376
  maxprot 0x00000007
 initprot 0x00000005
   nsects 6
    flags 0x0

Mac OS X 10.12.2:

otool -l /usr/lib/dyld
/usr/lib/dyld:
Mach header
      magic cputype cpusubtype  caps    filetype ncmds sizeofcmds      flags
 0xfeedfacf 16777223          3  0x00           7    14       1696 0x00000085
Load command 0
      cmd LC_SEGMENT_64
  cmdsize 552
  segname __TEXT
   vmaddr 0x0000000000000000
   vmsize 0x000000000003e000
  fileoff 0
 filesize 253952
  maxprot 0x00000007
 initprot 0x00000005
   nsects 6
    flags 0x0

Notice that vmaddr is now 0x0. I wrote a hack to add the base address of the
TEXT segment of dyld to the notifier address and this gets gdb to start
successfully:
https://github.com/stefanmb/binutils-gdb/commit/ee5bfeff7174f6e0b515f87d8ba2214ce45a02aa

With the patch "info shared" appears to work correctly.

I am now encountering further issues related to shared libraries and forking
(children are seeing SIGSEGV after my patch), but I have not had a chance to
investigate further. I will update this issue if I find more relevant info.

This behaviour reproduces on the latest gdb (7.12.50.20161217-git).

Does anyone know what has to be done to fix this issue properly?

I am available to test potential fixes, but I require some support to resolve
this problem properly.

Thank you very much for your help!

-- 
You are receiving this mail because:
You are on the CC list for the bug.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]