21 марта 2020 г., в 20:13, Andrew Fish <af...@apple.com> написал(а):



On Mar 21, 2020, at 3:28 AM, Vitaly Cheptsov <chept...@ispras.ru> wrote:

Hello,

Andrey, thanks for the hint, it was very helpful. I rewrote the GDB scripts to work with LLDB[1] and was able to debug OVMF built with CLANGPDB. While it is still quite dirty, at the very least it works.

Unfortunately the experience was close to terrible. I may certainly do something wrong, but it is clear that PDB and LLDB do not support each other well enough. After spending several hours on playing with the tools my conclusion is that LLDB is simply not suited for UEFI PDB debugging, and we really want DWARF  as there is no other opensource debugger that supports PDB on macOS and Linux

In case somebody knows workarounds here are the issues I faced:

1. All integer alias typedefs are discarded in favour of underlying types. This way EFI_STATUS and EFI_TPL become unsigned long long, CHAR8 becomes char, and CHAR16 becomes unsigned short. It does not look like LLDB has the original types anywhere at all, and it also does not have them registered.

    frame #0: 0x000000007fe242aa DxeCore.dll`CoreAllocatePoolPagesI(PoolType=EfiBootServicesData, NoPages=1, Granularity=4096, NeedGuard='\0') at Pool.c:322
   319      return NULL;
   320    }
   321 
-> 322    Buffer = CoreAllocatePoolPages (PoolType, NoPages, Granularity, NeedGuard);
   323    CoreReleaseMemoryLock ();
   324 
   325    if (Buffer != NULL) {
(lldb) p Status
(unsigned long long) $3 = 0

Structures work more or less fine, but for simpler types like strings we are out of even potential pretty-printing.


Vitaly,

You can teach lldb about types. There is some example code here: https://github.com/tianocore/edk2/blob/master/EmulatorPkg/Unix/lldbefi.py

2. Global variables are not accessible. I am not sure what happens, but they either seem to not relocate or conflict with the other names:

(lldb) p gST
error: Couldn't materialize: couldn't get the value of variable ::gST: read memory from 0x6e18 failed
error: errored out in DoExecute, couldn't PrepareToExecuteJITExpression
(lldb) p &gST
error: Couldn't materialize: couldn't get the value of variable ::gST: read memory from 0x6e18 failed
error: errored out in DoExecute, couldn't PrepareToExecuteJITExpression


That is strange as globals usually work best? The common issue I've seen is getting the slide wrong. The EFI modules are linked at a value near zero and relocated into memory, so the slide represents that adjustment. 

You can use `image dump sections` and ` image dump symtab` to see lldb's view of symbols. More info here [1]. 

3. Quite a number of crashes.

In most cases autocompletion by tab press causes a crash. E.g.

b I<TAB>

So will do printing of a GUID, e.g. p gEfiGlobalVariableGuid.

This may have to do with Python compatibility as Xcode 11 LLDB that uses Python 3 generally crashes more often than MacPorts LLDB 9.0. Surprisingly structures work more or less fine.


You can tell lldb to use the older Python like this (from the Terminal.app):
$ defaults write com.apple.dt.lldb DefaultPythonVersion 2

4. Ctrl+C does not produce a valid backtrace. When I break with a breakpoint, I see a proper stacktrace with more than one entry, with function prototypes and values. When I break with Ctrl+C I only see some weird backtrace with most of the entries missing regardless of frame position:

(lldb) bt
* thread #1, stop reason = signal SIGTRAP
  * frame #0: 0x000000007fe4c5f3 DxeCore.dll

Probably more and all the unintuitive stuff like the lack of more functional TUI, but it is hard to remember all the trials.


For the macOS API clang emits frame pointers, so you can walk the stack without symbols. You could try adding the compiler flag to emit the frame pointers. 



On macOS the Mach-O and dSYM have a UUID (dwarfdump -u) that is indexed by Spotlight (mdfind "com_apple_xcode_dsym_uuids == *") [2]
This should be the UUID in the debug directory entry and you can use that to lookup the symbols like this:

module = target.AddModule (None, None, uuid)
SBError = target.SetModuleLoadAddress (module, LoadAddress + TeAdjust)

Also lldb has built in help for commands, but it is kind of terse since it is autogenerated from the C++ swig. 
(lldb) script help (lldb.target.AddModule)
Help on method AddModule in module lldb:

AddModule(self, *args) method of lldb.SBTarget instance
    AddModule(SBTarget self, SBModule module) -> bool
    AddModule(SBTarget self, char const * path, char const * triple, char const * uuid) -> SBModule
    AddModule(SBTarget self, char const * path, char const * triple, char const * uuid_cstr, char const * symfile) -> SBModule
    AddModule(SBTarget self, SBModuleSpec module_spec) -> SBModule

The minimum  you need to symbolicate a frame is uuid, LoadAddress, and PC. 


Thanks,

Andrew Fish


Best wishes,
Vitaly

20 марта 2020 г., в 22:14, Andrew Fish <af...@apple.com> написал(а):



On Mar 20, 2020, at 8:13 AM, Vitaly Cheptsov <chept...@ispras.ru> wrote:

Hello,

We noticed that the original bugzilla, which intended to add new LLVM toolchain support[1], also wanted to bring ELF format support with DWARF debugging information. For some reason this did not make its way into EDK II, and we are currently wondering, how can one debug binaries built with LLVM 9.0.

For macOS and XCODE5 toolchain we use GDB scripts based on Andrei Warkentin’s work, which allow us to integrate with QEMU and VMware[2]. It is likely that they should work with little to no work on Linux with CLANG38/GCC5 with GDB once again. However, CLANGPDB apparently is using PDB debugging information, which I believe is not handled with GDB.

Could you please provide the details on the matter and let us know about the recommended route?
— Is dropping CLANGELF just a temporary measure and it should be resubmitted again?
— Should LLDB, which seems to be aware of PDB, be used instead of GDB, when building with CLANGPDB? If so, did anybody try that?


Vitaly,

I've not tried the CLANGPDB path, but if you want to connect lldb to QEMU you need to set  plugin.process.gdb-remote.target-definition-file [1] to [2]. 

[1]  lldb -o "settings set plugin.process.gdb-remote.target-definition-file x86_64_target_definition.py" -o "gdb-remote 9000"

Thanks,

Andrew Fish



_._,_._,_

Groups.io Links:

You receive all messages sent to this group.

View/Reply Online (#56072) | | Mute This Topic | New Topic

Your Subscription | Contact Group Owner | Unsubscribe [arch...@mail-archive.com]

_._,_._,_
E.g. this is what happens when I type «b In<TAB>». I cannot reproduce it with 
stock LLDB.

(lldb) b In0  lldb                     0x0000000102638705 
llvm::sys::PrintStackTrace(llvm::raw_ostream&) + 37
1  lldb                     0x0000000102637d77 llvm::sys::RunSignalHandlers() + 
39
2  lldb                     0x0000000102638d58 SignalHandler(int) + 264
3  libsystem_platform.dylib 0x00007fff6ca5642d _sigtramp + 29
4  libsystem_platform.dylib 000000000000000000 _sigtramp + 2472188912
5  LLDB                     0x0000000102dbf200 
llvm::BinaryStreamReader::BinaryStreamReader(llvm::BinaryStream&) + 32
6  LLDB                     0x00000001030ba527 
llvm::pdb::ModuleDebugStreamRef::reload() + 39
7  LLDB                     0x0000000102d589ff 
lldb_private::npdb::CompileUnitIndex::GetOrCreateCompiland(unsigned short) + 319
8  LLDB                     0x0000000102d72077 
lldb_private::npdb::SymbolFileNativePDB::ParseCompileUnitAtIndex(unsigned int) 
+ 119
9  LLDB                     0x00000001029cf71d 
lldb_private::SymbolVendor::GetCompileUnitAtIndex(unsigned long) + 221
10 LLDB                     0x000000010288659a 
lldb_private::Module::GetCompileUnitAtIndex(unsigned long) + 106
11 LLDB                     0x000000010289fb10 
lldb_private::SearchFilter::DoCUIteration(std::__1::shared_ptr<lldb_private::Module>
 const&, lldb_private::SymbolContext const&, lldb_private::Searcher&) + 208
12 LLDB                     0x000000010289f7b3 
lldb_private::SearchFilter::DoModuleIteration(lldb_private::SymbolContext 
const&, lldb_private::Searcher&) + 419
13 LLDB                     0x000000010289f5f4 
lldb_private::SearchFilter::Search(lldb_private::Searcher&) + 180
14 LLDB                     0x0000000102e5563d 
lldb_private::CommandCompletions::SourceFileCompleter::DoCompletion(lldb_private::SearchFilter*)
 + 29
15 LLDB                     0x0000000102e54c28 
lldb_private::CommandCompletions::SourceFiles(lldb_private::CommandInterpreter&,
 lldb_private::CompletionRequest&, lldb_private::SearchFilter*) + 200
16 LLDB                     0x0000000102e555ed 
lldb_private::CommandCompletions::InvokeCommonCompletionCallbacks(lldb_private::CommandInterpreter&,
 unsigned int, lldb_private::CompletionRequest&, lldb_private::SearchFilter*) + 
93
17 LLDB                     0x000000010293b331 
lldb_private::CommandObjectRegexCommand::HandleCompletion(lldb_private::CompletionRequest&)
 + 33
18 LLDB                     0x00000001029310e8 
lldb_private::CommandInterpreter::HandleCompletionMatches(lldb_private::CompletionRequest&)
 + 424
19 LLDB                     0x000000010293135d 
lldb_private::CommandInterpreter::HandleCompletion(char const*, char const*, 
char const*, int, int, lldb_private::StringList&, lldb_private::StringList&) + 
349
20 LLDB                     0x0000000102871eaa 
lldb_private::IOHandlerDelegate::IOHandlerComplete(lldb_private::IOHandler&, 
char const*, char const*, char const*, int, int, lldb_private::StringList&, 
lldb_private::StringList&) + 90
21 LLDB                     0x0000000102872547 
lldb_private::IOHandlerEditline::AutoCompleteCallback(char const*, char const*, 
char const*, int, int, lldb_private::StringList&, lldb_private::StringList&, 
void*) + 55
22 LLDB                     0x00000001029155fe 
lldb_private::Editline::TabCommand(int) + 110
23 LLDB                     0x0000000102917931 
lldb_private::Editline::ConfigureEditor(bool)::$_13::__invoke(editline*, int) + 
33
24 libedit.3.dylib          0x00007fff6a3fc7db el_wgets + 484
25 libedit.3.dylib          0x00007fff6a4078bb el_gets + 37
26 LLDB                     0x0000000102916df7 
lldb_private::Editline::GetLine(std::__1::basic_string<char, 
std::__1::char_traits<char>, std::__1::allocator<char> >&, bool&) + 439
27 LLDB                     0x00000001028727bc 
lldb_private::IOHandlerEditline::GetLine(std::__1::basic_string<char, 
std::__1::char_traits<char>, std::__1::allocator<char> >&, bool&) + 60
28 LLDB                     0x0000000102872f3e 
lldb_private::IOHandlerEditline::Run() + 190
29 LLDB                     0x000000010285a3cb 
lldb_private::Debugger::ExecuteIOHandlers() + 123
30 LLDB                     0x000000010293589c 
lldb_private::CommandInterpreter::RunCommandInterpreter(bool, bool, 
lldb_private::CommandInterpreterRunOptions&) + 156
31 LLDB                     0x00000001026deb91 
lldb::SBDebugger::RunCommandInterpreter(bool, bool) + 209
32 lldb                     0x0000000102623665 Driver::MainLoop() + 2853
33 lldb                     0x00000001026245d2 main + 1634
34 libdyld.dylib            0x00007fff6c85d7fd start + 1
35 libdyld.dylib            0x000000000000000f start + 2474256403
Stack dump:
0.  Program arguments: /Applications/Xcode.app/Contents/Developer/usr/bin/lldb 
-o settings set plugin.process.gdb-remote.target-definition-file 
Scripts/x86_64_target_definition.py -o gdb-remote 8864 -o target modules add -s 
GdbSyms/Bin/X64_CLANGPDB/GdbSyms.pdb GdbSyms/Bin/X64_CLANGPDB/GdbSyms.dll -o 
command script import Scripts/lldb_uefi.py -o command script add -c 
lldb_uefi.ReloadUefi reload-uefi -o reload-uefi -o b DebugBreak 
./maclldb.tool: line 33: 37553 Segmentation fault: 11  "$LLDB" -o "settings set 
plugin.process.gdb-remote.target-definition-file 
Scripts/x86_64_target_definition.py" -o "gdb-remote $LLDB_PORT" -o "target 
modules add -s GdbSyms/Bin/X64_CLANGPDB/GdbSyms.pdb 
GdbSyms/Bin/X64_CLANGPDB/GdbSyms.dll" -o "command script import 
Scripts/lldb_uefi.py" -o "command script add -c lldb_uefi.ReloadUefi 
reload-uefi" -o "reload-uefi" -o "b DebugBreak"

This I cannot reproduce with stock GDB either:
(lldb) p mDebugInfoTableHeader
0  lldb                     0x0000000102e13705 
llvm::sys::PrintStackTrace(llvm::raw_ostream&) + 37
1  lldb                     0x0000000102e12d77 llvm::sys::RunSignalHandlers() + 
39
2  lldb                     0x0000000102e13d58 SignalHandler(int) + 264
3  libsystem_platform.dylib 0x00007fff6ca5642d _sigtramp + 29
4  libsystem_platform.dylib 0xaae108ecfd74df7c _sigtramp + 2429516652
5  LLDB                     0x000000010359e200 
llvm::BinaryStreamReader::BinaryStreamReader(llvm::BinaryStream&) + 32
6  LLDB                     0x0000000103899527 
llvm::pdb::ModuleDebugStreamRef::reload() + 39
7  LLDB                     0x00000001035379ff 
lldb_private::npdb::CompileUnitIndex::GetOrCreateCompiland(unsigned short) + 319
8  LLDB                     0x0000000103540a77 
lldb_private::npdb::PdbAstBuilder::ParseAllNamespacesPlusChildrenOf(llvm::Optional<llvm::StringRef>)
 + 663
9  LLDB                     0x00000001035414e2 
lldb_private::npdb::PdbAstBuilder::ParseDeclsForContext(clang::DeclContext&) + 
82
10 LLDB                     0x0000000103550fef 
lldb_private::npdb::SymbolFileNativePDB::ParseDeclsForContext(lldb_private::CompilerDeclContext)
 + 63
11 LLDB                     0x000000010315604c 
lldb_private::ClangASTContext::DeclContextFindDeclByName(void*, 
lldb_private::ConstString, bool) + 668
12 LLDB                     0x00000001031627b9 
lldb_private::CompilerDeclContext::FindDeclByName(lldb_private::ConstString, 
bool) + 57
13 LLDB                     0x00000001032f1b76 
lldb_private::ClangExpressionDeclMap::FindExternalVisibleDecls(lldb_private::NameSearchContext&,
 std::__1::shared_ptr<lldb_private::Module>, 
lldb_private::CompilerDeclContext&, unsigned int) + 1014
14 LLDB                     0x00000001032f1334 
lldb_private::ClangExpressionDeclMap::FindExternalVisibleDecls(lldb_private::NameSearchContext&)
 + 628
15 LLDB                     0x00000001032e63b6 
lldb_private::ClangASTSource::FindExternalVisibleDeclsByName(clang::DeclContext 
const*, clang::DeclarationName) + 1174
16 LLDB                     0x000000010635e802 
clang::DeclContext::lookup(clang::DeclarationName) const + 754
17 LLDB                     0x0000000105ff1f66 LookupDirect(clang::Sema&, 
clang::LookupResult&, clang::DeclContext const*) + 86
18 LLDB                     0x0000000105fee3e9 
clang::Sema::CppLookupName(clang::LookupResult&, clang::Scope*) + 3257
19 LLDB                     0x0000000105ff1795 
clang::Sema::LookupName(clang::LookupResult&, clang::Scope*, bool) + 725
20 LLDB                     0x0000000105d66a63 
clang::Sema::ClassifyName(clang::Scope*, clang::CXXScopeSpec&, 
clang::IdentifierInfo*&, clang::SourceLocation, clang::Token const&, bool, 
std::__1::unique_ptr<clang::CorrectionCandidateCallback, 
std::__1::default_delete<clang::CorrectionCandidateCallback> >) + 419
21 LLDB                     0x0000000105b0ac14 
clang::Parser::TryAnnotateName(bool, 
std::__1::unique_ptr<clang::CorrectionCandidateCallback, 
std::__1::default_delete<clang::CorrectionCandidateCallback> >) + 484
22 LLDB                     0x0000000105aeb55a 
clang::Parser::ParseStatementOrDeclarationAfterAttributes(llvm::SmallVector<clang::Stmt*,
 32u>&, clang::Parser::AllowedConstructsKind, clang::SourceLocation*, 
clang::Parser::ParsedAttributesWithRange&) + 394
23 LLDB                     0x0000000105aeb279 
clang::Parser::ParseStatementOrDeclaration(llvm::SmallVector<clang::Stmt*, 
32u>&, clang::Parser::AllowedConstructsKind, clang::SourceLocation*) + 201
24 LLDB                     0x0000000105af263c 
clang::Parser::ParseCompoundStatementBody(bool) + 1644
25 LLDB                     0x0000000105af3131 
clang::Parser::ParseFunctionStatementBody(clang::Decl*, 
clang::Parser::ParseScope&) + 161
26 LLDB                     0x0000000105b09780 
clang::Parser::ParseFunctionDefinition(clang::ParsingDeclarator&, 
clang::Parser::ParsedTemplateInfo const&, clang::Parser::LateParsedAttrList*) + 
2608
27 LLDB                     0x0000000105a84045 
clang::Parser::ParseDeclGroup(clang::ParsingDeclSpec&, 
clang::DeclaratorContext, clang::SourceLocation*, clang::Parser::ForRangeInit*) 
+ 1781
28 LLDB                     0x0000000105b08a37 
clang::Parser::ParseDeclOrFunctionDefInternal(clang::Parser::ParsedAttributesWithRange&,
 clang::ParsingDeclSpec&, clang::AccessSpecifier) + 695
29 LLDB                     0x0000000105b084e3 
clang::Parser::ParseDeclarationOrFunctionDefinition(clang::Parser::ParsedAttributesWithRange&,
 clang::ParsingDeclSpec*, clang::AccessSpecifier) + 339
30 LLDB                     0x0000000105b06c57 
clang::Parser::ParseExternalDeclaration(clang::Parser::ParsedAttributesWithRange&,
 clang::ParsingDeclSpec*) + 2535
31 LLDB                     0x0000000105b05d97 
clang::Parser::ParseTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&) + 679
32 LLDB                     0x0000000105a71855 clang::ParseAST(clang::Sema&, 
bool, bool) + 453
33 LLDB                     0x0000000105a71672 
clang::ParseAST(clang::Preprocessor&, clang::ASTConsumer*, clang::ASTContext&, 
bool, clang::TranslationUnitKind, clang::CodeCompleteConsumer*, bool) + 194
34 LLDB                     0x00000001033094a1 
lldb_private::ClangExpressionParser::ParseInternal(lldb_private::DiagnosticManager&,
 clang::CodeCompleteConsumer*, unsigned int, unsigned int) + 1729
35 LLDB                     0x0000000103315793 
lldb_private::ClangUserExpression::Parse(lldb_private::DiagnosticManager&, 
lldb_private::ExecutionContext&, lldb_private::ExecutionPolicy, bool, bool) + 
499
36 LLDB                     0x00000001030deaf5 
lldb_private::UserExpression::Evaluate(lldb_private::ExecutionContext&, 
lldb_private::EvaluateExpressionOptions const&, llvm::StringRef, 
llvm::StringRef, lldb_private::SharingPtr<lldb_private::ValueObject>&, 
lldb_private::Status&, unsigned int, std::__1::basic_string<char, 
std::__1::char_traits<char>, std::__1::allocator<char> >*, 
std::__1::shared_ptr<lldb_private::Module>*) + 1701
37 LLDB                     0x0000000103241542 
lldb_private::Target::EvaluateExpression(llvm::StringRef, 
lldb_private::ExecutionContextScope*, 
lldb_private::SharingPtr<lldb_private::ValueObject>&, 
lldb_private::EvaluateExpressionOptions const&, std::__1::basic_string<char, 
std::__1::char_traits<char>, std::__1::allocator<char> >*) + 418
38 LLDB                     0x000000010364dd06 
lldb_private::CommandObjectExpression::EvaluateExpression(llvm::StringRef, 
lldb_private::Stream*, lldb_private::Stream*, 
lldb_private::CommandReturnObject*) + 566
39 LLDB                     0x000000010364ec56 
lldb_private::CommandObjectExpression::DoExecute(llvm::StringRef, 
lldb_private::CommandReturnObject&) + 1270
40 LLDB                     0x000000010311877b 
lldb_private::CommandObjectRaw::Execute(char const*, 
lldb_private::CommandReturnObject&) + 427
41 LLDB                     0x000000010310fd25 
lldb_private::CommandInterpreter::HandleCommand(char const*, 
lldb_private::LazyBool, lldb_private::CommandReturnObject&, 
lldb_private::ExecutionContext*, bool, bool) + 2805
42 LLDB                     0x0000000103113d61 
lldb_private::CommandInterpreter::IOHandlerInputComplete(lldb_private::IOHandler&,
 std::__1::basic_string<char, std::__1::char_traits<char>, 
std::__1::allocator<char> >&) + 657
43 LLDB                     0x0000000103051f9d 
lldb_private::IOHandlerEditline::Run() + 285
44 LLDB                     0x00000001030393cb 
lldb_private::Debugger::ExecuteIOHandlers() + 123
45 LLDB                     0x000000010311489c 
lldb_private::CommandInterpreter::RunCommandInterpreter(bool, bool, 
lldb_private::CommandInterpreterRunOptions&) + 156
46 LLDB                     0x0000000102ebdb91 
lldb::SBDebugger::RunCommandInterpreter(bool, bool) + 209
47 lldb                     0x0000000102dfe665 Driver::MainLoop() + 2853
48 lldb                     0x0000000102dff5d2 main + 1634
49 libdyld.dylib            0x00007fff6c85d7fd start + 1
50 libdyld.dylib            0x000000000000000f start + 2474256403
Stack dump:
0.  Program arguments: /Applications/Xcode.app/Contents/Developer/usr/bin/lldb 
-o settings set plugin.process.gdb-remote.target-definition-file 
Scripts/x86_64_target_definition.py -o gdb-remote 8864 -o target modules add -s 
GdbSyms/Bin/X64_CLANGPDB/GdbSyms.pdb GdbSyms/Bin/X64_CLANGPDB/GdbSyms.dll -o 
command script import Scripts/lldb_uefi.py -o command script add -c 
lldb_uefi.ReloadUefi reload-uefi -o reload-uefi -o b DebugBreak 
./maclldb.tool: line 33: 37722 Segmentation fault: 11  "$LLDB" -o "settings set 
plugin.process.gdb-remote.target-definition-file 
Scripts/x86_64_target_definition.py" -o "gdb-remote $LLDB_PORT" -o "target 
modules add -s GdbSyms/Bin/X64_CLANGPDB/GdbSyms.pdb 
GdbSyms/Bin/X64_CLANGPDB/GdbSyms.dll" -o "command script import 
Scripts/lldb_uefi.py" -o "command script add -c lldb_uefi.ReloadUefi 
reload-uefi" -o "reload-uefi" -o "b DebugBreak"

Attachment: signature.asc
Description: Message signed with OpenPGP

Reply via email to