Issue |
132901
|
Summary |
The lldb step command skips commands without debugging information
|
Labels |
new issue
|
Assignees |
|
Reporter |
Guo-yyds
|
Now I am doing a project, need to use lldb debugging, I have provided lldb debug information, but some code does not have debug_line, this time in the step debugging, it will become stepin, I also checked the source code, is there any way to directly skip the part without source code?
Here is the source code.
CommandObjectThread.cpp
```cpp
void DoExecute(Args &command, CommandReturnObject &result) override {
std::cout << "[lldb ghn] DoExecute" << m_cmd_name << std::endl;
Process *process = m_exe_ctx.GetProcessPtr();
bool synchronous_execution = m_interpreter.GetSynchronous();
const uint32_t num_threads = process->GetThreadList().GetSize();
Thread *thread = nullptr;
if (command.GetArgumentCount() == 0) {
thread = GetDefaultThread();
if (thread == nullptr) {
result.AppendError("no selected thread in process");
return;
}
} else {
const char *thread_idx_cstr = command.GetArgumentAtIndex(0);
uint32_t step_thread_idx;
if (!llvm::to_integer(thread_idx_cstr, step_thread_idx)) {
result.AppendErrorWithFormat("invalid thread index '%s'.\n",
thread_idx_cstr);
return;
}
thread =
process->GetThreadList().FindThreadByIndexID(step_thread_idx).get();
if (thread == nullptr) {
result.AppendErrorWithFormat(
"Thread index %u is out of range (valid values are 0 - %u).\n",
step_thread_idx, num_threads);
return;
}
}
if (m_step_type == eStepTypeScripted) {
if (m_class_options.GetName().empty()) {
result.AppendErrorWithFormat("empty class name for scripted step.");
return;
} else if (!GetDebugger().GetScriptInterpreter()->CheckObjectExists(
m_class_options.GetName().c_str())) {
result.AppendErrorWithFormat(
"class for scripted step: \"%s\" does not exist.",
m_class_options.GetName().c_str());
return;
}
}
if (m_options.m_end_line != LLDB_INVALID_LINE_NUMBER &&
m_step_type != eStepTypeInto) {
result.AppendErrorWithFormat(
"end line option is only valid for step into");
return;
}
const bool abort_other_plans = false;
const lldb::RunMode stop_other_threads = m_options.m_run_mode;
// This is a bit unfortunate, but not all the commands in this command
// object support only while stepping, so I use the bool for them.
bool bool_stop_other_threads;
if (m_options.m_run_mode == eAllThreads)
bool_stop_other_threads = false;
else if (m_options.m_run_mode == eOnlyDuringStepping)
bool_stop_other_threads = (m_step_type != eStepTypeOut);
else
bool_stop_other_threads = true;
ThreadPlanSP new_plan_sp;
Status new_plan_status;
if (m_step_type == eStepTypeInto) {
StackFrame *frame = thread->GetStackFrameAtIndex(0).get();
assert(frame != nullptr);
if (frame->HasDebugInformation()) {
std::cout << "[lldb ghn] HasDebugInformation" << std::endl;
AddressRange range;
SymbolContext sc = frame->GetSymbolContext(eSymbolContextEverything);
if (m_options.m_end_line != LLDB_INVALID_LINE_NUMBER) {
llvm::Error err =
sc.GetAddressRangeFromHereToEndLine(m_options.m_end_line, range);
if (err) {
result.AppendErrorWithFormatv("invalid end-line option: {0}.",
llvm::toString(std::move(err)));
return;
}
} else if (m_options.m_end_line_is_block_end) {
Status error;
Block *block = frame->GetSymbolContext(eSymbolContextBlock).block;
if (!block) {
result.AppendErrorWithFormat("Could not find the current block.");
return;
}
AddressRange block_range;
Address pc_address = frame->GetFrameCodeAddress();
block->GetRangeContainingAddress(pc_address, block_range);
if (!block_range.GetBaseAddress().IsValid()) {
result.AppendErrorWithFormat(
"Could not find the current block address.");
return;
}
lldb::addr_t pc_offset_in_block =
pc_address.GetFileAddress() -
block_range.GetBaseAddress().GetFileAddress();
lldb::addr_t range_length =
block_range.GetByteSize() - pc_offset_in_block;
range = AddressRange(pc_address, range_length);
} else {
// enter
range = sc.line_entry.range;
// 创建一个 StreamFile 对象,输出到 stdout
lldb_private::StreamFile stream(stdout, false); // false 表示不自动关闭输出流
range.DumpDebug(&stream);
}
new_plan_sp = thread->QueueThreadPlanForStepInRange(
abort_other_plans, range,
frame->GetSymbolContext(eSymbolContextEverything),
m_options.m_step_in_target.c_str(), stop_other_threads,
new_plan_status, m_options.m_step_in_avoid_no_debug,
m_options.m_step_out_avoid_no_debug);
if (new_plan_sp && !m_options.m_avoid_regexp.empty()) {
// not enter
ThreadPlanStepInRange *step_in_range_plan =
static_cast<ThreadPlanStepInRange *>(new_plan_sp.get());
step_in_range_plan->SetAvoidRegexp(m_options.m_avoid_regexp.c_str());
}
} else{
std::cout << "[lldb ghn] don't HasDebugInformation" << std::endl;
// new_plan_sp = thread->QueueThreadPlanForStepSingleInstruction(
// false, abort_other_plans, bool_stop_other_threads,
// new_plan_status);
new_plan_sp = thread->QueueThreadPlanForStepOut(
abort_other_plans, nullptr, false, bool_stop_other_threads,
eVoteYes, eVoteNoOpinion,
thread->GetSelectedFrameIndex(DoNoSelectMostRelevantFrame),
new_plan_status, m_options.m_step_out_avoid_no_debug);
}
} else if (m_step_type == eStepTypeOver) {
StackFrame *frame = thread->GetStackFrameAtIndex(0).get();
if (frame->HasDebugInformation())
new_plan_sp = thread->QueueThreadPlanForStepOverRange(
abort_other_plans,
frame->GetSymbolContext(eSymbolContextEverything).line_entry,
frame->GetSymbolContext(eSymbolContextEverything),
stop_other_threads, new_plan_status,
m_options.m_step_out_avoid_no_debug);
else{
// new_plan_sp = thread->QueueThreadPlanForStepSingleInstruction(
// true, abort_other_plans, bool_stop_other_threads, new_plan_status);
new_plan_sp = thread->QueueThreadPlanForStepOut(
abort_other_plans, nullptr, false, bool_stop_other_threads,
eVoteYes, eVoteNoOpinion,
thread->GetSelectedFrameIndex(DoNoSelectMostRelevantFrame),
new_plan_status, m_options.m_step_out_avoid_no_debug);
}
} else if (m_step_type == eStepTypeTrace) {
new_plan_sp = thread->QueueThreadPlanForStepSingleInstruction(
false, abort_other_plans, bool_stop_other_threads, new_plan_status);
} else if (m_step_type == eStepTypeTraceOver) {
new_plan_sp = thread->QueueThreadPlanForStepSingleInstruction(
true, abort_other_plans, bool_stop_other_threads, new_plan_status);
} else if (m_step_type == eStepTypeOut) {
new_plan_sp = thread->QueueThreadPlanForStepOut(
abort_other_plans, nullptr, false, bool_stop_other_threads, eVoteYes,
eVoteNoOpinion,
thread->GetSelectedFrameIndex(DoNoSelectMostRelevantFrame),
new_plan_status, m_options.m_step_out_avoid_no_debug);
} else if (m_step_type == eStepTypeScripted) {
new_plan_sp = thread->QueueThreadPlanForStepScripted(
abort_other_plans, m_class_options.GetName().c_str(),
m_class_options.GetStructuredData(), bool_stop_other_threads,
new_plan_status);
} else {
result.AppendError("step type is not supported");
return;
}
// If we got a new plan, then set it to be a controlling plan (User level
// Plans should be controlling plans so that they can be interruptible).
// Then resume the process.
if (new_plan_sp) {
new_plan_sp->SetIsControllingPlan(true);
new_plan_sp->SetOkayToDiscard(false);
if (m_options.m_step_count > 1) {
if (!new_plan_sp->SetIterationCount(m_options.m_step_count)) {
result.AppendWarning(
"step operation does not support iteration count.");
}
}
process->GetThreadList().SetSelectedThreadByID(thread->GetID());
const uint32_t iohandler_id = process->GetIOHandlerID();
StreamString stream;
Status error;
if (synchronous_execution)
error = process->ResumeSynchronous(&stream);
else
error = process->Resume();
if (!error.Success()) {
result.AppendMessage(error.AsCString());
return;
}
// There is a race condition where this thread will return up the call
// stack to the main command handler and show an (lldb) prompt before
// HandlePrivateEvent (from PrivateStateThread) has a chance to call
// PushProcessIOHandler().
process->SyncIOHandler(iohandler_id, std::chrono::seconds(2));
if (synchronous_execution) {
// If any state changed events had anything to say, add that to the
// result
if (stream.GetSize() > 0)
result.AppendMessage(stream.GetString());
process->GetThreadList().SetSelectedThreadByID(thread->GetID());
result.SetDidChangeProcessState(true);
result.SetStatus(eReturnStatusSuccessFinishNoResult);
} else {
result.SetStatus(eReturnStatusSuccessContinuingNoResult);
}
} else {
result.SetError(std::move(new_plan_status));
}
}
```
I also tried to modify it, but there is still a problem.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs