DerekSelander / dsdump

An improved nm + Objective-C & Swift class-dump
1.12k stars 111 forks source link

segfaults on M1 Mac for arch arm64e #31

Open DanboDuan opened 2 years ago

DanboDuan commented 2 years ago

I build dsdump on M1 Mac myself. It works fine for x86_64 arch library, but fails for arm64e arch library

  1. first run

    dsdump -sc /usr/libexec/sharingd
    Multiple arches found: [ x86_64 | arm64e ]
    Use --arches (-a) (or ARCH env var) to specify arch

    so add -a x86_64, fine

    dsdump -sc /usr/libexec/sharingd -a x86_64
    protocol sharingd.SDContactStoreInterface // 5 requirements
    protocol sharingd.SDAirDropHashStore // 12 requirements
    
    struct __C.Name {
    
    // Properties
    var _rawValue : NSString
    }
    
    class __C.CFString {
    class __C.CGImage {
    struct __C.FileProtectionType {
    
    // Properties
    var _rawValue : NSString
    }
    
    struct __C.FileAttributeKey {
    
    // Properties
    var _rawValue : NSString
    }
    
    struct sharingd.SDAirDropContactHashManagerContext {
    
    // Properties
    let systemMonitor : SDCUSystemMonitorInterface // +0x0
    let contactStore : SDContactStoreInterface // +0x8
    let hashStore : SDAirDropHashStore // +0x30
    let notificationCenter : NSNotificationCenter // +0x40
    let distributedNotificationCenter : NSNotificationCenter // +0x48
    let coalescerMinDelay : Double // +0x50
    let coalescerMaxDelay : Double // +0x58
    }
    
    class sharingd.SDXPCHelperImageCache : NSObject /usr/lib/libobjc.A.dylib {
    // ObjC -> Swift bridged methods
    0x1001d7730  @objc SDXPCHelperImageCache.init <stripped>
    
    // Swift methods
    0x1001d4a20  class func static SDXPCHelperImageCache.clearCacheWithSync(_:) // method
    0x1001d52d0  class func static SDXPCHelperImageCache.purgeAvatars() // method
    0x1001d55d0  class func static SDXPCHelperImageCache.evict(contactIdentifier:) // method
    0x1001d6440  class func static SDXPCHelperImageCache.setImage(_:forKey:contactIDs:) // method
    0x1001d6950  class func static SDXPCHelperImageCache.cacheIsEmpty() // method
    0x1001d6af0  class func static SDXPCHelperImageCache.imageForKey(_:contactIDs:) // method
    0x1001d6ff0  class func static SDXPCHelperImageCache.cacheCount() // method
    }
    
    enum sharingd.CacheError {
    
    // Properties
    WARNING: couldn't find address 0x0 (0x0) in binary!
    case imageDestinationCreateFailed : ��
    WARNING: couldn't find address 0x0 (0x0) in binary!
    case imageDestinationFinalizeFailed : ��
    WARNING: couldn't find address 0x0 (0x0) in binary!
    case imageSourceCreateFailed : ��
    }
    
    class sharingd.SDAirDropHashStoreCDB : _SwiftObject /usr/lib/swift/libswiftCore.dylib {
    
    // Properties
    var reader : CUKeyValueStoreReader<NSData, NSData>
    var stagedAdditions : SDAirDropHashStoreEntry
    var stagedDeletedIDs : Set<String>
    var loaded : Bool
    var destroyed : Bool
    
    // Swift methods
    0x1001dbfa0  func SDAirDropHashStoreCDB.rebuildRequired.getter // getter
    0x1001dc150  func SDAirDropHashStoreCDB.load() // method
    0x1001dc7e0  func SDAirDropHashStoreCDB.stageAddEntries(_:) // method
    0x1001dd0f0  func SDAirDropHashStoreCDB.stageDeleteEntriesForContact(withID:) // method
    0x1001dd710  func SDAirDropHashStoreCDB.persist() // method
    0x1001df710  func SDAirDropHashStoreCDB.destroy() // method
    0x1001df9b0  func SDAirDropHashStoreCDB.contact(forLongHash:) // method
    0x1001dff80  func SDAirDropHashStoreCDB.contacts(forLongHash:) // method
    0x1001e0cc0  func SDAirDropHashStoreCDB.contact(forMediumHash:) // method
    0x1001e1280  func SDAirDropHashStoreCDB.contacts(forMediumHash:) // method
    0x1001e1c40  func SDAirDropHashStoreCDB.contains(shortHash:) // method
    }
    
    class sharingd.SDContactChangeHistoryEvent : _SwiftObject /usr/lib/swift/libswiftCore.dylib {
    // Swift methods
    }
    
    class sharingd.SDContactChangeHistoryDropEverythingEvent : SDContactChangeHistoryEvent { }
    
    class sharingd.SDContactChangeHistoryAddEvent : SDContactChangeHistoryEvent {
    
    // Properties
    let contact : CNContact
    
    // Swift methods
    }
    
    class sharingd.SDContactChangeHistoryDeleteEvent : SDContactChangeHistoryEvent {
    
    // Properties
    let contactIdentifier : String
    
    // Swift methods
    }
    
    class sharingd.SDContactChangeHistoryUpdateEvent : SDContactChangeHistoryEvent {
    
    // Properties
    let contact : CNContact
    
    // Swift methods
    }
    
    class sharingd.SDContactStore : _SwiftObject /usr/lib/swift/libswiftCore.dylib, SDContactStoreInterface {
    
    // Properties
    let didChangeNotificationName : Name
    let meContactDidChangeNotificationName : Name
    let contactStore : CNContactStore
    
    // Swift methods
    0x1001eda90  func <stripped> // method
    0x1001edbd0  func <stripped> // method
    0x1001ee120  func <stripped> // method
    }
    
    enum sharingd.SDRunState {
    
    // Properties
    case notStarted
    case inProgress
    case completed
    case failed
    case skip
    }
    
    class sharingd.OnceManager : _SwiftObject /usr/lib/swift/libswiftCore.dylib {
    
    // Properties
    var onceList : Set<Int> // +0x10 (0x8)
    
    // Swift methods
    }
    
    class sharingd.PushableTimer : _SwiftObject /usr/lib/swift/libswiftCore.dylib {
    
    // Properties
    WARNING: couldn't find address 0x0 (0x0) in binary!
    let noLaterThan : {� // +0x19 (0x0)
    let timer : OS_dispatch_source_timer // +0x0 (0x8)
    
    // Swift methods
    0x1001f03f0  class func PushableTimer.__allocating_init(fireAt:noLaterThan:queue:handler:) // init
    0x1001f0510  func PushableTimer.reschedule(deadline:) // method
    0x1001f0720  func PushableTimer.resume() // method
    0x1001f0740  func PushableTimer.cancel() // method
    }
    
    class sharingd.SDB389BubbleMonitor : _SwiftObject /usr/lib/swift/libswiftCore.dylib {
    
    // Properties
    WARNING: couldn't find address 0x0 (0x0) in binary!
    var allDevices :  empty-list
    var queue : OS_dispatch_queue?
    var updateHandler : ()?
    WARNING: couldn't find address 0x0 (0x0) in binary!
    var lostHandler :  empty-list
    let bubbleScanner : SFDeviceDiscovery
    let rssiThreshold : Int
    WARNING: couldn't find address 0x0 (0x0) in binary!
    var bubbleDevices :  empty-list
    
    // Swift methods
    0x1001f0860  func SDB389BubbleMonitor.allDevices.getter // getter
    0x1001f0890  func SDB389BubbleMonitor.allDevices.setter // setter
    0x1001f08d0  func SDB389BubbleMonitor.allDevices.modify // modifyCoroutine
    0x1001f0910  func SDB389BubbleMonitor.queue.getter // getter
    0x1001f0950  func SDB389BubbleMonitor.queue.setter // setter
    0x1001f0990  func SDB389BubbleMonitor.queue.modify // modifyCoroutine
    0x1001f09c0  func SDB389BubbleMonitor.inBubbleCount.getter // getter
    0x1001f09d0  func SDB389BubbleMonitor.updateHandler.getter // getter
    0x1001f0a10  func SDB389BubbleMonitor.updateHandler.setter // setter
    0x1001f0a80  func SDB389BubbleMonitor.updateHandler.modify // modifyCoroutine
    0x1001f0ab0  func SDB389BubbleMonitor.lostHandler.getter // getter
    0x1001f0af0  func SDB389BubbleMonitor.lostHandler.setter // setter
    0x1001f0b60  func SDB389BubbleMonitor.lostHandler.modify // modifyCoroutine
    0x1001f0b90  func SDB389BubbleMonitor.closestB389sInBubble.getter // getter
    }
    
    class sharingd.InstanceCounter {
    struct sharingd.IntegerPacker {
    
    // Properties
    let sourcesPerTarget : Int
    }
    
    enum sharingd.PackError {
    
    // Properties
    case wrongPackLength
    }
    
    struct sharingd.ShortHash {
    
    // Properties
    WARNING: couldn't find address 0x0 (0x0) in binary!
    let storage : g� // +0x0
    }
    
    struct sharingd.MediumHash {
    
    // Properties
    let shortHash : ShortHash // +0x0
    WARNING: couldn't find address 0x0 (0x0) in binary!
    let lastMediumByte : A� // +0x2
    }
    
    struct sharingd.LongHash {
    
    // Properties
    WARNING: couldn't find address 0x0 (0x0) in binary!
    let storage : u� // +0x0
    }
    
    struct sharingd.SDHashStoreContact {
    
    // Properties
    let id : String // +0x0
    let emailOrPhone : String // +0x10
    }
    
    struct sharingd.SDAirDropHashStoreEntry {
    
    // Properties
    let hashStoreContact : SDHashStoreContact // +0x0
    let longHash : LongHash // +0x20
    let mediumHash : MediumHash // +0x40
    }
    
    class sharingd.SDAirDropHandlerIPA : SDAirDropHandler {
    // ObjC -> Swift bridged methods
    0x1001f6ec0  @objc SDAirDropHandlerIPA.canHandleTransfer <stripped>
    0x1001f6ed0  @objc SDAirDropHandlerIPA.transferTypes <stripped>
    0x1001f6f10  @objc SDAirDropHandlerIPA.suitableContentsDescription <stripped>
    0x1001f7450  @objc SDAirDropHandlerIPA.singleItemActionTitle <stripped>
    0x1001f7510  @objc SDAirDropHandlerIPA.initWithTransfer:bundleIdentifier: <stripped>
    }
    
    class sharingd.SDDeferrableOperation : NSObject /usr/lib/libobjc.A.dylib {
    
    // Properties
    let identifier : String // +0x8 (0x10)
    WARNING: couldn't find address 0x0 (0x0) in binary!
    var preventUntilDate : �� // +0x0 (0x0)
    let operation : (_:) // +0x0 (0x10)
    let queue : OS_dispatch_queue // +0x0 (0x8)
    WARNING: couldn't find address 0x0 (0x0) in binary!
    var timedReasons : String // +0x0 (0x8)
    var reasons : Set<String> // +0x0 (0x8)
    var pendingOperation : Bool // +0x0 (0x1)
    var mainTimer : OS_dispatch_source_timer? // +0x0 (0x8)
    
    // ObjC -> Swift bridged methods
    0x1001f7770  @objc SDDeferrableOperation.initWithIdentifier:queue:operation: <stripped>
    0x1001f7d00  @objc SDDeferrableOperation.addReason: <stripped>
    0x1001f8340  @objc SDDeferrableOperation.removeReason: <stripped>
    0x1001f91f0  @objc SDDeferrableOperation.pushPreventionDateForReason:newDate: <stripped>
    0x1001f97e0  @objc SDDeferrableOperation.scheduleOperation <stripped>
    0x1001fb5d0  @objc SDDeferrableOperation.returnPreventUntilDate <stripped>
    0x1001fb680  @objc SDDeferrableOperation.returnHasActiveTimer <stripped>
    0x1001fb6a0  @objc SDDeferrableOperation.init <stripped>
    0x1001fb700  @objc SDDeferrableOperation..cxx_destruct <stripped>
    
    // Swift methods
    0x1001f7820  func <stripped> // method
    0x1001f7d20  func <stripped> // method
    0x1001f83e0  func <stripped> // method
    0x1001f92d0  func <stripped> // method
    0x1001f9810  func <stripped> // method
    0x1001f9f00  func <stripped> // method
    0x1001face0  func <stripped> // method
    0x1001fb010  func <stripped> // method
    }
    
    enum sharingd.SDAirDropHashError {
    
    // Properties
    case hashesAreIncorrect
    case storeNotLoaded
    case storeDestroyed
    case contactIDDecodeFailed
    case contactFieldDecodeFailed
    case rateLimited
    }
    
    class sharingd.SDAirDropContactHashManager : NSObject /usr/lib/libobjc.A.dylib {
    
    // Properties
    let context : SDAirDropContactHashManagerContext // +0x8 (0x60)
    let contactUpdateCoalescer : CUCoalescer // +0x68 (0x8)
    let meCardUpdateCoalescer : CUCoalescer // +0x70 (0x8)
    let systemMonitor : SDCUSystemMonitorInterface // +0x78 (0x8)
    let hashManagerQ : OS_dispatch_queue // +0x80 (0x8)
    let bucket : SFTokenBucketWithDups // +0x88 (0x8)
    let contactStore : SDContactStoreInterface // +0x90 (0x28)
    var hashDB : SDAirDropHashStore // +0xb8 (0x10)
    let notificationCenter : NSNotificationCenter // +0xc8 (0x8)
    let distributedNotificationCenter : NSNotificationCenter // +0xd0 (0x8)
    var activated : Bool // +0xd8 (0x1)
    var meCardInfo : SDAirDropHashStoreEntry // +0xe0 (0x10)
    var hashesUpdatedSuccessfully : Bool // +0xf0 (0x1)
    
    // ObjC -> Swift bridged methods
    0x1001ff880  @objc SDAirDropContactHashManager.init <stripped>
    0x100201730  @objc SDAirDropContactHashManager.cmfSyncAgentBlockListDidChange <stripped>
    0x1002017b0  @objc SDAirDropContactHashManager.contactStoreDidChange <stripped>
    0x100201ac0  @objc SDAirDropContactHashManager.meCardDidChange <stripped>
    0x100209100  @objc SDAirDropContactHashManager..cxx_destruct <stripped>
    
    // Swift methods
    }

but fails for -a arm64e

dsdump -sc /usr/libexec/sharingd -a arm64e
[1]    93873 segmentation fault  dsdump -sc /usr/libexec/sharingd -a arm64e

figured adding details from the crash log might help!

Translated Report (Full Report Below)
-------------------------------------

Process:               dsdump [93873]
Path:                  /Users/USER/*/dsdump
Identifier:            dsdump
Version:               ???
Code Type:             ARM-64 (Native)
Parent Process:        zsh [85399]
Responsible:           iTerm2 [68109]
User ID:               501

Date/Time:             2021-12-02 00:17:51.5711 +0800
OS Version:            macOS 12.0.1 (21A559)
Report Version:        12
Anonymous UUID:        BB59D4CE-08F2-006C-360E-EEAD995E580A

Sleep/Wake UUID:       4097F3DD-96B7-4D54-9F2A-E450B888E5DC

Time Awake Since Boot: 150000 seconds
Time Since Wake:       3078 seconds

System Integrity Protection: enabled

Crashed Thread:        0  Dispatch queue: com.apple.main-thread

Exception Type:        EXC_BAD_ACCESS (SIGSEGV)
Exception Codes:       KERN_INVALID_ADDRESS at 0x000000000000002c
Exception Codes:       0x0000000000000001, 0x000000000000002c
Exception Note:        EXC_CORPSE_NOTIFY

Termination Reason:    Namespace SIGNAL, Code 11 Segmentation fault: 11
Terminating Process:   exc handler [93873]

VM Region Info: 0x2c is not in any region.  Bytes before following region: 4332765140
      REGION TYPE                    START - END         [ VSIZE] PRT/MAX SHRMOD  REGION DETAIL
      UNUSED SPACE AT START
--->  
      __TEXT                      10240c000-1027e0000    [ 3920K] r-x/r-x SM=COW  ...USER/*/dsdump

Thread 0 Crashed::  Dispatch queue: com.apple.main-thread
0   dsdump                                 0x102446a64 -[XRMachOLibrary(Opcode) parseDYLDExports] + 36 (XRMachOLibrary+Opcode.mm:362)
1   dsdump                                 0x102446a64 -[XRMachOLibrary(Opcode) parseDYLDExports] + 36 (XRMachOLibrary+Opcode.mm:362)
2   dsdump                                 0x10242a01c -[XRMachOLibrary initWithPath:] + 7296 (XRMachOLibrary.mm:380)
3   dsdump                                 0x10244f4c4 main + 396 (main.m:59)
4   dyld                                   0x102bfd0f4 start + 520

Thread 0 crashed with ARM Thread State (64-bit):
    x0: 0x0000000000000000   x1: 0x00000001025956fd   x2: 0x000000000000000d   x3: 0x0000000000000029
    x4: 0x0000000000000078   x5: 0x000000000000004f   x6: 0x0000000000000074   x7: 0x0000000000000660
    x8: 0x000000013f804080   x9: 0x4036311255e20031  x10: 0x000000013f8050a0  x11: 0x0000000000db9a45
   x12: 0x000000000000001d  x13: 0x0000000000000000  x14: 0x0000000100000000  x15: 0x0000000102594d39
   x16: 0x000000010282ccba  x17: 0x000000010242d290  x18: 0x0000000000000000  x19: 0x0000000102ca4060
   x20: 0x000000010244f338  x21: 0x0000000102c58070  x22: 0x0000000000000000  x23: 0x0000000000000000
   x24: 0x0000000000000000  x25: 0x0000000000000000  x26: 0x0000000000000000  x27: 0x0000000000000000
   x28: 0x0000000000000000   fp: 0x000000016d9f2510   lr: 0x0000000102446a64
    sp: 0x000000016d9f2470   pc: 0x0000000102446a64 cpsr: 0x60000000
   far: 0x000000000000002c  esr: 0x92000006 (Data Abort) byte read Translation fault

Binary Images:
       0x10240c000 -        0x1027dffff dsdump (*) <52ee2ef6-2c2d-399c-88cc-50166185a29f> /Users/USER/*/dsdump
       0x102bf8000 -        0x102c57fff dyld (*) <86a8ba48-8bb4-3b30-9cda-051f73c74f44> /usr/lib/dyld
               0x0 - 0xffffffffffffffff ??? (*) <00000000-0000-0000-0000-000000000000> ???

External Modification Summary:
  Calls made by other processes targeting this process:
    task_for_pid: 0
    thread_create: 0
    thread_set_state: 0
  Calls made by this process:
    task_for_pid: 0
    thread_create: 0
    thread_set_state: 0
  Calls made by all processes on this machine:
    task_for_pid: 23
    thread_create: 0
    thread_set_state: 1460

VM Region Summary:
ReadOnly portion of Libraries: Total=653.7M resident=0K(0%) swapped_out_or_unallocated=653.7M(100%)
Writable regions: Total=668.4M written=0K(0%) resident=0K(0%) swapped_out=0K(0%) unallocated=668.4M(100%)

                                VIRTUAL   REGION 
REGION TYPE                        SIZE    COUNT (non-coalesced) 
===========                     =======  ======= 
Activity Tracing                   256K        1 
Kernel Alloc Once                   32K        1 
MALLOC                           155.2M       15 
MALLOC guard page                   96K        5 
MALLOC_MEDIUM (reserved)         120.0M        1         reserved VM address space (unallocated)
MALLOC_NANO (reserved)           384.0M        1         reserved VM address space (unallocated)
STACK GUARD                       56.0M        1 
Stack                             8176K        1 
__AUTH                             221K       47 
__AUTH_CONST                      2871K      124 
__DATA                            2652K      118 
__DATA_CONST                      3575K      125 
__DATA_DIRTY                       232K       50 
__LINKEDIT                       572.4M        3 
__OBJC_CONST                       259K       29 
__OBJC_RO                         81.8M        1 
__OBJC_RW                         3088K        1 
__TEXT                            81.3M      132 
__UNICODE                          588K        1 
dyld private memory               1024K        1 
mapped file                       4704K        1 
shared memory                       32K        2 
===========                     =======  ======= 
TOTAL                              1.4G      661 
TOTAL, minus reserved VM space   973.9M      661 

-----------
Full Report
-----------

{"app_name":"dsdump","timestamp":"2021-12-02 00:17:51.00 +0800","app_version":"","slice_uuid":"52ee2ef6-2c2d-399c-88cc-50166185a29f","build_version":"","platform":1,"share_with_app_devs":0,"is_first_party":1,"bug_type":"309","os_version":"macOS 12.0.1 (21A559)","incident_id":"634C16A5-45FD-4569-8C0A-57028A085718","name":"dsdump"}
{
  "uptime" : 150000,
  "procLaunch" : "2021-12-02 00:17:51.5507 +0800",
  "procRole" : "Unspecified",
  "version" : 2,
  "userID" : 501,
  "deployVersion" : 210,
  "modelCode" : "MacBookPro17,1",
  "procStartAbsTime" : 3658611329111,
  "coalitionID" : 737,
  "osVersion" : {
    "train" : "macOS 12.0.1",
    "build" : "21A559",
    "releaseType" : "User"
  },
  "captureTime" : "2021-12-02 00:17:51.5711 +0800",
  "incident" : "634C16A5-45FD-4569-8C0A-57028A085718",
  "bug_type" : "309",
  "pid" : 93873,
  "procExitAbsTime" : 3658611811387,
  "translated" : false,
  "cpuType" : "ARM-64",
  "procName" : "dsdump",
  "procPath" : "\/Users\/USER\/*\/dsdump",
  "parentProc" : "zsh",
  "parentPid" : 85399,
  "coalitionName" : "com.googlecode.iterm2
DerekSelander commented 2 years ago

@DanboDuan thanks, will look into arm64e support hopefully over the holidays