debugging - lldb unresolved breakpoint via c++ api -


i have got executable module icoretest.exe, wich dynamicly loaded library irtest.rs. want debug via lldb c++ api.

when create "icoretest.exe" process under lldb throug lldb::sbtarget::launch(..); works fine. fine, mean can set breakpoints breakpointcreatebylocation , when debugger stops on event sblistener.waitforevent();

problems begins when want attach running process.

  1. create target , attach process

    m_debugdata->currenttarget=m_debugdata>debugger.createtarget(executable.c_str());  m_debugdata->currentprocess = m_debugdata>currenttarget.attachtoprocesswithname(m_debugdata->listener, processname.c_str(), false, error); 
  2. load module "irtest.rs"

      auto module = m_debugdata->currenttarget.addmodule("irtest.rs", "i386-pc-windows-msvc", nullptr); 
  3. after lldb stops on "ntdll.dll`dbgbreakpoint + 1"

  4. i execute command m_debugdata->currentprocess.continue();
  5. so, icoretest.exe running..
  6. add breakpoint m_debugdata->currenttarget.breakpointcreatebylocation("irtest.st", 58);
  7. the added breakpoint not triggered

after print existing breakpoints using following code:

void lldbrunner::printbreakpoints()     {         (int = 0; < m_debugdata->currenttarget.getnumbreakpoints(); i++)         {             auto bp = m_debugdata->currenttarget.getbreakpointatindex(i);              (int j = 0; j < bp.getnumlocations(); j++)             {                 auto loc = bp.getlocationatindex(j);                  lldb::sbstream stream;                 loc.getdescription(stream, lldb::descriptionlevel::edescriptionlevelfull);                 auto str = stream.getdata();             }         }     } 

and output was:

1.1: = irtest.rs`add + 421 @ irtest.st:58, address = irtest.rs[0x10001525], unresolved, hit count = 0

which means breakpoint unresolved..why? :)

also! when use lldb command line breakpoint resolved, , working:

(lldb) attach -p 17448 process 17448 stopped * thread #1: tid = 0x0ae0, 0x77bc8d21 ntdll.dll`dbgbreakpoint + 1, stop reason = exception 0x80000003 encountered @ address 0x77bc8d20     frame #0: 0x77bc8d21 ntdll.dll`dbgbreakpoint + 1 ntdll.dll`dbgbreakpoint: ->  0x77bc8d21 <+1>: retl     0x77bc8d22 <+2>: int3     0x77bc8d23 <+3>: int3     0x77bc8d24 <+4>: int3  executable module set "icoretest.exe". architecture set to: i386-pc-windows-msvc. (lldb) b irtest.st:58 breakpoint 1: = irtest.rs`add + 421 @ irtest.st:58, address = 0x07ca1525 (lldb) b current breakpoints: 1: file = 'irtest.st', line = 58, exact_match = 0, locations = 1, resolved = 1, hit count = 0   1.1: = irtest.rs`add + 421 @ irtest.st:58, address = 0x07ca1525, resolved, hit count = 0  (lldb) c process 17448 resuming process 17448 stopped * thread #6: tid = 0x2560, 0x07ca1525 irtest.rs`add(x1=2, x2=42, x3=(range = 1, min_scale = -4095, max_scale = 4095)) + 421 @ irtest.st:58, stop reason = breakpoint 1.1     frame #0: 0x07ca1525 irtest.rs`add(x1=2, x2=42, x3=(range = 1, min_scale = -4095, max_scale = 4095)) + 421 @ irtest.st:58    55              i, j : int;    56       end_var    57 -> 58           tmpinteg();    59    60    61 (lldb) 

update:

i write simple program wich reproduce bug

prog.cpp:

#include <cstdio>  void dosomething(void);  void dosomething(void) {   int loop = 0;   loop += 1;   loop += 2;   loop += 3; }  int main(void)` {   printf("start \n");    while(1)   {     dosomething();     }    return 0; } 

compile it..

gcc prog.cpp -g -o0 

when i`m trying set break point

m_debugdata->currenttarget.breakpointcreatebylocation("prog.cpp", 7); 

i same result

1.1: = a.exe`dosomething() + 6 @ prog.cpp:7, address = a.exe[0x00401356], unresolved, hit count = 0  

my little research:

i compare lldb behavior in 2 versions:

  1. launch new process(is ok)
  2. attach process(broken)

i found in method

lldb::break_id_t process::createbreakpointsite (const breakpointlocationsp &owner, bool use_hardware) 

line..

load_addr = owner->getaddress().getopcodeloadaddress (&gettarget()); 

return lldb_invalid_address in version when attach process.

callstack:

liblldb.dll!lldb_private::process::createbreakpointsite(const std::shared_ptr<lldb_private::breakpointlocation> & owner, bool use_hardware) line 2094   c++     liblldb.dll!lldb_private::breakpointlocation::resolvebreakpointsite() line 523  c++     liblldb.dll!lldb_private::breakpointlocationlist::addlocation(const lldb_private::address & addr, bool resolve_indirect_symbols, bool * new_location) line 254  c++     liblldb.dll!lldb_private::breakpoint::addlocation(const lldb_private::address & addr, bool * new_location) line 102 c++     liblldb.dll!lldb_private::breakpointresolver::addlocation(lldb_private::address loc_addr, bool * new_location) line 214 c++     liblldb.dll!lldb_private::breakpointresolver::setscmatchesbyline(lldb_private::searchfilter & filter, lldb_private::symbolcontextlist & sc_list, bool skip_prologue, const char * log_ident) line 184   c++     liblldb.dll!lldb_private::breakpointresolverfileline::searchcallback(lldb_private::searchfilter & filter, lldb_private::symbolcontext & context, lldb_private::address * addr, bool containing) line 94 c++     liblldb.dll!lldb_private::searchfilter::domoduleiteration(const lldb_private::symbolcontext & context, lldb_private::searcher & searcher) line 190  c++     liblldb.dll!lldb_private::searchfilter::search(lldb_private::searcher & searcher) line 118  c++     liblldb.dll!lldb_private::breakpointresolver::resolvebreakpoint(lldb_private::searchfilter & filter) line 62    c++     liblldb.dll!lldb_private::breakpoint::resolvebreakpoint() line 355  c++     liblldb.dll!lldb_private::target::addbreakpoint(std::shared_ptr<lldb_private::breakpoint> bp_sp, bool internal) line 695    c++     liblldb.dll!lldb_private::target::createbreakpoint(std::shared_ptr<lldb_private::searchfilter> & filter_sp, std::shared_ptr<lldb_private::breakpointresolver> & resolver_sp, bool internal, bool request_hardware, bool resolve_indirect_symbols) line 672  c++     liblldb.dll!lldb_private::target::createbreakpoint(const lldb_private::filespeclist * containingmodules, const lldb_private::filespec & file, unsigned int line_no, unsigned __int64 offset, lldb_private::lazybool check_inlines, lldb_private::lazybool skip_prologue, bool internal, bool hardware, lldb_private::lazybool move_to_nearest_code) line 411    c++     liblldb.dll!lldb::sbtarget::breakpointcreatebylocation(const lldb::sbfilespec & sb_file_spec, unsigned int line, unsigned __int64 offset) line 832  c++     liblldb.dll!lldb::sbtarget::breakpointcreatebylocation(const lldb::sbfilespec & sb_file_spec, unsigned int line) line 803   c++     liblldb.dll!lldb::sbtarget::breakpointcreatebylocation(const char * file, unsigned int line) line 796   c++     consoleapplication1.exe!debugger::lldbrunner::setbreakpoint(std::basic_string<char,std::char_traits<char>,std::allocator<char> > file, unsigned int line) line 204  c++     consoleapplication1.exe!main() line 28  c++ 

update 2:

i print 'a.exe' module sections using following code:

for (int = 0; < m_debugdata->currenttarget.getnummodules(); i++) {     auto module = m_debugdata->currenttarget.getmoduleatindex(i);      auto modulename = module.getfilespec().getfilename();      (int j = 0; j < module.getnumsections(); j++)     {         auto section = module.getsectionatindex(j);          auto sectionname = section.getname();         auto addr = section.getloadaddress(m_debugdata->currenttarget);         auto isvalid = lldb_invalid_address != addr;          std::cout << "module: " << modulename << "; section: " << sectionname << "; isvalid: " << isvalid << std::endl;     } } 

an output was:

state changed unknown->stopped module: a.exe; section: .text; isvalid: 0 module: a.exe; section: .data; isvalid: 0 module: a.exe; section: .rdata; isvalid: 0 module: a.exe; section: .eh_frame; isvalid: 0 module: a.exe; section: .bss; isvalid: 0 module: a.exe; section: .idata; isvalid: 0 module: a.exe; section: .crt; isvalid: 0 module: a.exe; section: .tls; isvalid: 0 module: a.exe; section: .debug_aranges; isvalid: 0 module: a.exe; section: .debug_info; isvalid: 0 module: a.exe; section: .debug_abbrev; isvalid: 0 module: a.exe; section: .debug_line; isvalid: 0 module: a.exe; section: .debug_frame; isvalid: 0 

it's hard certainty, python apis , command line apis not entirely same. both have own set of things internally before running "actual" command requested. debugging on windows not mature on other platforms, in part because there not lot of people using yet. suggest reporting bug on lldb bug tracker.

in meantime, maybe can try creating target manually, , setting breakpoint before attach process. don't know if work, resolving breakpoint dynamically when module loaded, versus trying resolve when drop breakpoint down 2 different codepaths, it's possible work if breakpoint there.


Comments

Popular posts from this blog

unity3d - Rotate an object to face an opposite direction -

angular - Is it possible to get native element for formControl? -

javascript - Why jQuery Select box change event is now working? -