Skip to content

Commit

Permalink
Re-commit "Introduce ObjectFileBreakpad"
Browse files Browse the repository at this point in the history
This re-commits r348592, which was reverted due to a failing test on
macos.

The issue was that I was passing a null pointer for the
"CreateMemoryInstance" callback when registering ObjectFileBreakpad,
which caused crashes when attemping to load modules from memory. The
correct thing to do is to pass a callback which always returns a null
pointer (as breakpad files are never loaded in inferior memory).

It turns out that there is only one test which exercises this code path,
and it's mac-only, so I've create a new test which should run everywhere
(except windows, as one cannot delete an executable which is being run).
Unfortunately, this test still fails on linux for other reasons, but at
least it gives us something to aim for.

The original commit message was:
This patch adds the scaffolding necessary for lldb to recognise symbol
files generated by breakpad. These (textual) files contain just enough
information to be able to produce a backtrace from a crash
dump. This information includes:
- UUID, architecture and name of the module
- line tables
- list of symbols
- unwind information

A minimal breakpad file could look like this:
MODULE Linux x86_64 0000000024B5D199F0F766FFFFFF5DC30 a.out
INFO CODE_ID 00000000B52499D1F0F766FFFFFF5DC3
FILE 0 /tmp/a.c
FUNC 1010 10 0 _start
1010 4 4 0
1014 5 5 0
1019 5 6 0
101e 2 7 0
PUBLIC 1010 0 _start
STACK CFI INIT 1010 10 .cfa: $rsp 8 + .ra: .cfa -8 + ^
STACK CFI 1011 $rbp: .cfa -16 + ^ .cfa: $rsp 16 +
STACK CFI 1014 .cfa: $rbp 16 +

Even though this data would normally be considered "symbol" information,
in the current lldb infrastructure it is assumed every SymbolFile object
is backed by an ObjectFile instance. So, in order to better interoperate
with the rest of the code (particularly symbol vendors).

In this patch I just parse the breakpad header, which is enough to
populate the UUID and architecture fields of the ObjectFile interface.
The rough plan for followup patches is to expose the individual parts of
the breakpad file as ObjectFile "sections", which can then be used by
other parts of the codebase (SymbolFileBreakpad ?) to vend the necessary
information.

Reviewers: clayborg, zturner, lemo, amccarth

Subscribers: mgorny, fedor.sergeev, markmentovai, lldb-commits

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

llvm-svn: 348773
  • Loading branch information
labath committed Dec 10, 2018
1 parent 9056f11 commit 1f6b247
Show file tree
Hide file tree
Showing 20 changed files with 558 additions and 1 deletion.
12 changes: 12 additions & 0 deletions lldb/include/lldb/Symbol/ObjectFile.h
Original file line number Diff line number Diff line change
Expand Up @@ -817,4 +817,16 @@ class ObjectFile : public std::enable_shared_from_this<ObjectFile>,

} // namespace lldb_private

namespace llvm {
template <> struct format_provider<lldb_private::ObjectFile::Type> {
static void format(const lldb_private::ObjectFile::Type &type,
raw_ostream &OS, StringRef Style);
};

template <> struct format_provider<lldb_private::ObjectFile::Strata> {
static void format(const lldb_private::ObjectFile::Strata &strata,
raw_ostream &OS, StringRef Style);
};
} // namespace llvm

#endif // liblldb_ObjectFile_h_
2 changes: 2 additions & 0 deletions lldb/lit/Modules/Breakpad/Inputs/bad-module-id-1.syms
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
MODULE Linux x86_64 E5894855+C35D+CCCCCCCCCCCCCCCCCCCC0 linux.out
PUBLIC 1000 0 _start
2 changes: 2 additions & 0 deletions lldb/lit/Modules/Breakpad/Inputs/bad-module-id-2.syms
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
MODULE Linux x86_64 E5894855C35DCCCCCCCCCCCCCCCCC linux.out
PUBLIC 1000 0 _start
2 changes: 2 additions & 0 deletions lldb/lit/Modules/Breakpad/Inputs/bad-module-id-3.syms
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
MODULE Linux x86_64 E58X4855C35DCCCCCCCCXCCCCCCCCCCC0 linux.out
PUBLIC 1000 0 _start
6 changes: 6 additions & 0 deletions lldb/lit/Modules/Breakpad/Inputs/identification-linux.syms
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
MODULE Linux x86_64 E5894855C35DCCCCCCCCCCCCCCCCCCCC0 linux.out
INFO CODE_ID 554889E55DC3CCCCCCCCCCCCCCCCCCCC
PUBLIC 1000 0 _start
STACK CFI INIT 1000 6 .cfa: $rsp 8 + .ra: .cfa -8 + ^
STACK CFI 1001 $rbp: .cfa -16 + ^ .cfa: $rsp 16 +
STACK CFI 1004 .cfa: $rbp 16 +
6 changes: 6 additions & 0 deletions lldb/lit/Modules/Breakpad/Inputs/identification-macosx.syms
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
MODULE mac x86_64 D98C0E682089AA1BEACD6A8C1F16707B0 mac.out
PUBLIC 0 0 _mh_execute_header
PUBLIC f30 0 start
STACK CFI INIT f30 6 .cfa: $rsp 8 + .ra: .cfa -8 + ^
STACK CFI f31 $rbp: .cfa -16 + ^ .cfa: $rsp 16 +
STACK CFI f34 .cfa: $rbp 16 +
4 changes: 4 additions & 0 deletions lldb/lit/Modules/Breakpad/Inputs/identification-windows.syms
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
MODULE windows x86 A0C9165780B5490981A1925EA62165C01 a.pdb
INFO CODE_ID 5C01672A4000 a.exe
FILE 1 c:\tmp\a.cpp
PUBLIC 1000 0 main
32 changes: 32 additions & 0 deletions lldb/lit/Modules/Breakpad/breakpad-identification.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
RUN: lldb-test object-file %p/Inputs/identification-linux.syms | FileCheck %s --check-prefix=LINUX
RUN: lldb-test object-file %p/Inputs/identification-macosx.syms | FileCheck %s --check-prefix=MAC
RUN: lldb-test object-file %p/Inputs/identification-windows.syms | FileCheck %s --check-prefix=WINDOWS
RUN: not lldb-test object-file %p/Inputs/bad-module-id-1.syms 2>&1 | FileCheck %s --check-prefix=ERROR
RUN: not lldb-test object-file %p/Inputs/bad-module-id-2.syms 2>&1 | FileCheck %s --check-prefix=ERROR
RUN: not lldb-test object-file %p/Inputs/bad-module-id-3.syms 2>&1 | FileCheck %s --check-prefix=ERROR

LINUX: Plugin name: breakpad
LINUX: Architecture: x86_64--linux
LINUX: UUID: 554889E5-5DC3-CCCC-CCCC-CCCCCCCCCCCC
LINUX: Executable: false
LINUX: Stripped: false
LINUX: Type: debug info
LINUX: Strata: user

MAC: Plugin name: breakpad
MAC: Architecture: x86_64--macosx
MAC: UUID: 680E8CD9-8920-1BAA-EACD-6A8C1F16707B
MAC: Executable: false
MAC: Stripped: false
MAC: Type: debug info
MAC: Strata: user

WINDOWS: Plugin name: breakpad
WINDOWS: Architecture: i386--windows
WINDOWS: UUID: 5716C9A0-B580-0949-81A1-925EA62165C0-01000000
WINDOWS: Executable: false
WINDOWS: Stripped: false
WINDOWS: Type: debug info
WINDOWS: Strata: user

ERROR: not recognised as an object file
1 change: 1 addition & 0 deletions lldb/lit/Modules/Breakpad/lit.local.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
config.suffixes = ['.test']
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
LEVEL = ../../make

CXX_SOURCES := main.cpp

include $(LEVEL)/Makefile.rules
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
"""
Test process attach/resume.
"""

from __future__ import print_function


import os
import time
import lldb
from lldbsuite.test.decorators import *
from lldbsuite.test.lldbtest import *
from lldbsuite.test import lldbutil

class TestDeletedExecutable(TestBase):

mydir = TestBase.compute_mydir(__file__)
NO_DEBUG_INFO_TESTCASE = True

@skipIfWindows # cannot delete a running executable
@expectedFailureAll(oslist=["linux"]) # determining the architecture of the process fails
def test(self):
self.build()
exe = self.getBuildArtifact("a.out")

popen = self.spawnSubprocess(exe)
self.addTearDownHook(self.cleanupSubprocesses)
os.remove(exe)

self.runCmd("process attach -p " + str(popen.pid))
self.runCmd("kill")
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#include <chrono>
#include <thread>

int main(int argc, char const *argv[])
{
lldb_enable_attach();

std::this_thread::sleep_for(std::chrono::seconds(30));
}
3 changes: 3 additions & 0 deletions lldb/source/API/SystemInitializerFull.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
#include "Plugins/LanguageRuntime/ObjC/AppleObjCRuntime/AppleObjCRuntimeV2.h"
#include "Plugins/LanguageRuntime/RenderScript/RenderScriptRuntime/RenderScriptRuntime.h"
#include "Plugins/MemoryHistory/asan/MemoryHistoryASan.h"
#include "Plugins/ObjectFile/Breakpad/ObjectFileBreakpad.h"
#include "Plugins/ObjectFile/ELF/ObjectFileELF.h"
#include "Plugins/ObjectFile/Mach-O/ObjectFileMachO.h"
#include "Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.h"
Expand Down Expand Up @@ -268,6 +269,7 @@ SystemInitializerFull::Initialize(const InitializerOptions &options) {
if (auto e = SystemInitializerCommon::Initialize(options))
return e;

breakpad::ObjectFileBreakpad::Initialize();
ObjectFileELF::Initialize();
ObjectFileMachO::Initialize();
ObjectFilePECOFF::Initialize();
Expand Down Expand Up @@ -525,6 +527,7 @@ void SystemInitializerFull::Terminate() {
PlatformDarwinKernel::Terminate();
#endif

breakpad::ObjectFileBreakpad::Terminate();
ObjectFileELF::Terminate();
ObjectFileMachO::Terminate();
ObjectFilePECOFF::Terminate();
Expand Down
11 changes: 11 additions & 0 deletions lldb/source/Plugins/ObjectFile/Breakpad/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
add_lldb_library(lldbPluginObjectFileBreakpad PLUGIN
ObjectFileBreakpad.cpp

LINK_LIBS
lldbCore
lldbHost
lldbSymbol
lldbUtility
LINK_COMPONENTS
Support
)
Loading

0 comments on commit 1f6b247

Please sign in to comment.