当前位置: 首页 > 知识库问答 >
问题:

用C++api解决lldb未解决的断点

姚臻
2023-03-14

我有可执行模块icoreTest.exe和动态加载库irtest.rs。我想通过lldb C++API调试它。

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);
  auto module = m_debugData->currentTarget.AddModule("IRTest.rs", "i386-pc-windows-msvc", nullptr);
void LLDBRunner::printBreakpoints()
    {
        for (int i = 0; i < m_debugData->currentTarget.GetNumBreakpoints(); i++)
        {
            auto bp = m_debugData->currentTarget.GetBreakpointAtIndex(i);

            for (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();
            }
        }
    }

1.1:where=irtest.rs`add+421 at irtest.st:58,地址=irtest.rs[0x10001525],未解析,命中数=0

这意味着我的断点没有解决..为什么?:)

还有!当我使用lldb命令行时,断点被解决,并且工作:

(lldb) attach -p 17448
Process 17448 stopped
* thread #1: tid = 0x0ae0, 0x77bc8d21 ntdll.dll`DbgBreakPoint + 1, stop reason = Exception 0x80000003 encountered at 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 to "iCoreTest.exe".
Architecture set to: i386-pc-windows-msvc.
(lldb) b IRTest.st:58
Breakpoint 1: where = IRTest.rs`Add + 421 at 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: where = IRTest.rs`Add + 421 at 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 at 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 at IRTest.st:58
   55              i, j : INT;
   56       END_VAR
   57
-> 58           tmpInteg();
   59
   60
   61
(lldb)
#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;
}
gcc prog.cpp -g -O0
m_debugData->currentTarget.BreakpointCreateByLocation("prog.cpp", 7);
1.1: where = a.exe`doSomething() + 6 at prog.cpp:7, address = a.exe[0x00401356], unresolved, hit count = 0 

我比较了两个版本中的lldb行为:

  1. 启动新进程(可以)
  2. 附加到进程(中断)

我发现在方法上

lldb::break_id_t
Process::CreateBreakpointSite (const BreakpointLocationSP &owner, bool use_hardware)
load_addr = owner->GetAddress().GetOpcodeLoadAddress (&GetTarget());
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++
for (int i = 0; i < m_debugData->currentTarget.GetNumModules(); i++)
{
    auto module = m_debugData->currentTarget.GetModuleAtIndex(i);

    auto moduleName = module.GetFileSpec().GetFilename();

    for (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;
    }
}
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

共有1个答案

郎经纶
2023-03-14

很难说清楚,但是python API和命令行API并不完全相同。在运行您请求的“实际”命令之前,它们都有自己的一组内部操作。Windows上的调试肯定不如其他平台上的成熟,部分原因是还没有很多人使用它。我建议将此报告为lldb bug跟踪器上的bug。

同时,也许您可以尝试手动创建一个目标,并在附加到进程之前设置断点。我不知道这是否行得通,但是在加载模块时动态地解析断点,与在删除断点时立即解析断点是两种不同的代码,所以如果断点已经存在,它可能行得通。

 类似资料:
  • 我想编写一个函数,返回一个布尔值,指示具有指定public_id的图像是否已经存在于我的Cloudinary空间中。 我可以使用以下代码将结果记录到控制台: 但是,我想将结果布尔值传递给另一个函数。使用返回语句会导致记录: 这与javascript Promises有关。不过,我似乎无法重组我的代码以使其正常工作。任何帮助都将不胜感激。

  • 我从git hub开始在我的android工作室下载flutter项目来学习,但是我只在这里AndroidManifest.xml文件中遇到这个问题,我还安装了所有依赖项。请解决我的问题。在这里输入图像描述 在此输入图像描述 在此输入图像描述

  • 我一直在尝试在应用程序上设置Firebase云消息。在我向应用程序添加FCM依赖项之前,一切都正常运行。我立即发现这个错误: 未能解析:firebase-messaging-15.0.0打开文件 以下是依赖关系; 我一整天都在读这样的答案,唯一有效的解决方案是删除代码最后一行“:-0”中的所有内容。 问题是,它会立即删除与FCM的连接。android编程新手,所以请原谅任何明显的疏忽。谢谢

  • 我试图遵循这里给出的例子:https://developer.android.com/topic/security/data 我已经在我的gradle中包含了必需的库: 然而,当我尝试使用代码时: 我得到一个未解决的引用:MasterKey错误。图书馆有那门课吗? 提前谢谢。

  • 我正试图在Karaf上开发一个OSGi WAB,其中包含REST API和来自定制服务的调用。然而,由于一些奇怪的原因,OSGi框架抱怨一个不令人满意的功能,。 我想知道: 我如何解决这个问题 什么是<code>osgi。组件bundle?为什么需要 为什么maven bundle插件(也就是bnd)在条目“Require Capability”中声明它 如果我需要在OSGi框架上安装它,我可以在

  • 我创建了一个带有初始化程序的Spring启动应用程序。 spring boot版本为2.1.3。释放 问题是我想在引导应用程序中包含JSP,但没有生成webapp文件夹。我在生成应用程序时选择了Spring MVC。 我在src/main/resources/templates文件夹中创建了一个jsp,并尝试用应用程序中的各种配置加载它。属性,例如, 但没有一个有效。我得到404白标错误。 我试图