Author: labath
Date: Wed Jan 16 04:42:57 2019
New Revision: 351330

URL: http://llvm.org/viewvc/llvm-project?rev=351330&view=rev
Log:
Teach the default symbol vendor to respect module.GetSymbolFileFileSpec()

Summary:
Adding a breakpad symbol file to an existing MachO module with "target symbols
add" currently works only if one's host platform is a mac. This is
because SymbolVendorMacOSX (which is the one responsible for loading
symbols for MachO files) is conditionally compiled for the mac platform.

While we will sooner or later have a special symbol vendor for breakpad
files (to enable more advanced searching), and so this flow could be
made to work through that, it's not clear to me whether this should be a
requirement for the "target symbols add" flow to work. After all, since
the user has explicitly specified the symbol file to use, the symbol
vendor plugin's job is pretty much done.

This patch teaches the default symbol vendor to respect module's symbol
file spec, and load the symbol from that file if it is specified (and no
plugin requests any special handling).

Reviewers: clayborg, zturner, lemo

Subscribers: lldb-commits

Differential Revision: https://reviews.llvm.org/D56589

Added:
    lldb/trunk/lit/SymbolFile/Breakpad/Inputs/basic-macho.yaml
    lldb/trunk/lit/SymbolFile/Breakpad/Inputs/symtab-macho.syms
    lldb/trunk/lit/SymbolFile/Breakpad/symtab-macho.test
Modified:
    lldb/trunk/source/Symbol/SymbolVendor.cpp

Added: lldb/trunk/lit/SymbolFile/Breakpad/Inputs/basic-macho.yaml
URL: 
http://llvm.org/viewvc/llvm-project/lldb/trunk/lit/SymbolFile/Breakpad/Inputs/basic-macho.yaml?rev=351330&view=auto
==============================================================================
--- lldb/trunk/lit/SymbolFile/Breakpad/Inputs/basic-macho.yaml (added)
+++ lldb/trunk/lit/SymbolFile/Breakpad/Inputs/basic-macho.yaml Wed Jan 16 
04:42:57 2019
@@ -0,0 +1,47 @@
+--- !mach-o
+FileHeader:      
+  magic:           0xFEEDFACF
+  cputype:         0x01000007
+  cpusubtype:      0x00000003
+  filetype:        0x00000002
+  ncmds:           9
+  sizeofcmds:      520
+  flags:           0x00000085
+  reserved:        0x00000000
+LoadCommands:    
+  - cmd:             LC_SEGMENT_64
+    cmdsize:         72
+    segname:         __PAGEZERO
+    vmaddr:          0
+    vmsize:          4294967296
+    fileoff:         0
+    filesize:        0
+    maxprot:         0
+    initprot:        0
+    nsects:          0
+    flags:           0
+  - cmd:             LC_SEGMENT_64
+    cmdsize:         152
+    segname:         __TEXT
+    vmaddr:          4294967296
+    vmsize:          4096
+    fileoff:         0
+    filesize:        4096
+    maxprot:         7
+    initprot:        5
+    nsects:          1
+    flags:           0
+    Sections:        
+      - sectname:        __text
+        segname:         __TEXT
+        addr:            0x0000000100000FF0
+        size:            6
+        offset:          0x00000FF0
+        align:           4
+        reloff:          0x00000000
+        nreloc:          0
+        flags:           0x80000400
+        reserved1:       0x00000000
+        reserved2:       0x00000000
+        reserved3:       0x00000000
+...

Added: lldb/trunk/lit/SymbolFile/Breakpad/Inputs/symtab-macho.syms
URL: 
http://llvm.org/viewvc/llvm-project/lldb/trunk/lit/SymbolFile/Breakpad/Inputs/symtab-macho.syms?rev=351330&view=auto
==============================================================================
--- lldb/trunk/lit/SymbolFile/Breakpad/Inputs/symtab-macho.syms (added)
+++ lldb/trunk/lit/SymbolFile/Breakpad/Inputs/symtab-macho.syms Wed Jan 16 
04:42:57 2019
@@ -0,0 +1,2 @@
+MODULE mac x86_64 601705B3B1227B7D39F9240E077D625B0 mac.out
+PUBLIC ff0 0 _start

Added: lldb/trunk/lit/SymbolFile/Breakpad/symtab-macho.test
URL: 
http://llvm.org/viewvc/llvm-project/lldb/trunk/lit/SymbolFile/Breakpad/symtab-macho.test?rev=351330&view=auto
==============================================================================
--- lldb/trunk/lit/SymbolFile/Breakpad/symtab-macho.test (added)
+++ lldb/trunk/lit/SymbolFile/Breakpad/symtab-macho.test Wed Jan 16 04:42:57 
2019
@@ -0,0 +1,21 @@
+# RUN: yaml2obj %S/Inputs/basic-macho.yaml > %T/symtab-macho.out
+# RUN: %lldb %T/symtab-macho.out -o "target symbols add -s symtab-macho.out 
%S/Inputs/symtab-macho.syms" \
+# RUN:   -s %s | FileCheck %s
+
+image dump symtab symtab-macho.out
+# CHECK-LABEL: (lldb) image dump symtab symtab-macho.out
+# CHECK: Symtab, file = {{.*}}symtab-macho.out, num_symbols = 1:
+# CHECK: Index   UserID DSX Type            File Address/Value Load Address    
   Size               Flags      Name
+# CHECK: [    0]      0   X Code            0x0000000100000ff0                 
   0x0000000000000006 0x00000000 _start
+
+# CHECK-LABEL: (lldb) image lookup -a 0x100000ff0 -v
+# CHECK: Address: symtab-macho.out[0x0000000100000ff0] 
(symtab-macho.out.__TEXT.__text + 0)
+# CHECK: Symbol: id = {0x00000000}, range = 
[0x0000000100000ff0-0x0000000100000ff6), name="_start"
+
+# CHECK-LABEL: (lldb) image lookup -n _start -v
+# CHECK: Address: symtab-macho.out[0x0000000100000ff0] 
(symtab-macho.out.__TEXT.__text + 0)
+# CHECK: Symbol: id = {0x00000000}, range = 
[0x0000000100000ff0-0x0000000100000ff6), name="_start"
+
+image lookup -a 0x100000ff0 -v
+image lookup -n _start -v
+exit

Modified: lldb/trunk/source/Symbol/SymbolVendor.cpp
URL: 
http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Symbol/SymbolVendor.cpp?rev=351330&r1=351329&r2=351330&view=diff
==============================================================================
--- lldb/trunk/source/Symbol/SymbolVendor.cpp (original)
+++ lldb/trunk/source/Symbol/SymbolVendor.cpp Wed Jan 16 04:42:57 2019
@@ -43,12 +43,19 @@ SymbolVendor *SymbolVendor::FindPlugin(c
   }
   // The default implementation just tries to create debug information using
   // the file representation for the module.
-  instance_ap.reset(new SymbolVendor(module_sp));
-  if (instance_ap.get()) {
-    ObjectFile *objfile = module_sp->GetObjectFile();
-    if (objfile)
-      instance_ap->AddSymbolFileRepresentation(objfile->shared_from_this());
+  ObjectFileSP sym_objfile_sp;
+  FileSpec sym_spec = module_sp->GetSymbolFileFileSpec();
+  if (sym_spec && sym_spec != module_sp->GetObjectFile()->GetFileSpec()) {
+    DataBufferSP data_sp;
+    offset_t data_offset = 0;
+    sym_objfile_sp = ObjectFile::FindPlugin(
+        module_sp, &sym_spec, 0, FileSystem::Instance().GetByteSize(sym_spec),
+        data_sp, data_offset);
   }
+  if (!sym_objfile_sp)
+    sym_objfile_sp = module_sp->GetObjectFile()->shared_from_this();
+  instance_ap.reset(new SymbolVendor(module_sp));
+  instance_ap->AddSymbolFileRepresentation(sym_objfile_sp);
   return instance_ap.release();
 }
 


_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to