Skip to content

Commit 2317347

Browse files
[lldb] Improve logging of failure to get register information from Target XML (#170478)
In https://discourse.llvm.org/t/does-lldb-qemu-support-dumping-x64-control-registers-such-as-cr3/89031 a user was not seeing certain registers when connected to QEMU. Turns out their LLDB build did not have libxml2 enabled. While logging is not the first thing most users will think of, it is something an expert can ask for to confirm whether they have XML support enabled. So in this PR I've shuffled the logic GetGDBServerRegisterInfo to better report problems in the log. The key one is when lldb does not have libxml2 but the server did say it supports qxfer:features. In this case we would have used it if we could, and the debug session will likely be degraded because we are not able to. https://sourceware.org/gdb/current/onlinedocs/gdb.html/General-Query-Packets.html#qXfer-target-description-read
1 parent 2612dc9 commit 2317347

File tree

2 files changed

+27
-10
lines changed

2 files changed

+27
-10
lines changed

lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -439,8 +439,16 @@ void ProcessGDBRemote::BuildDynamicRegisterInfo(bool force) {
439439
if (!arch_to_use.IsValid())
440440
arch_to_use = target_arch;
441441

442-
if (GetGDBServerRegisterInfo(arch_to_use))
442+
llvm::Error register_info_err = GetGDBServerRegisterInfo(arch_to_use);
443+
if (!register_info_err) {
444+
// We got the registers from target XML.
443445
return;
446+
}
447+
448+
Log *log = GetLog(GDBRLog::Process);
449+
LLDB_LOG_ERROR(log, std::move(register_info_err),
450+
"Failed to read register information from target XML: {0}");
451+
LLDB_LOG(log, "Now trying to use qRegisterInfo instead.");
444452

445453
char packet[128];
446454
std::vector<DynamicRegisterInfo::Register> registers;
@@ -5135,14 +5143,19 @@ void ProcessGDBRemote::AddRemoteRegisters(
51355143

51365144
// query the target of gdb-remote for extended target information returns
51375145
// true on success (got register definitions), false on failure (did not).
5138-
bool ProcessGDBRemote::GetGDBServerRegisterInfo(ArchSpec &arch_to_use) {
5139-
// Make sure LLDB has an XML parser it can use first
5140-
if (!XMLDocument::XMLEnabled())
5141-
return false;
5142-
5143-
// check that we have extended feature read support
5146+
llvm::Error ProcessGDBRemote::GetGDBServerRegisterInfo(ArchSpec &arch_to_use) {
5147+
// If the remote does not offer XML, does not matter if we would have been
5148+
// able to parse it.
51445149
if (!m_gdb_comm.GetQXferFeaturesReadSupported())
5145-
return false;
5150+
return llvm::createStringError(
5151+
llvm::inconvertibleErrorCode(),
5152+
"the debug server does not support \"qXfer:features:read\"");
5153+
5154+
if (!XMLDocument::XMLEnabled())
5155+
return llvm::createStringError(
5156+
llvm::inconvertibleErrorCode(),
5157+
"the debug server supports \"qXfer:features:read\", but LLDB does not "
5158+
"have XML parsing enabled (check LLLDB_ENABLE_LIBXML2)");
51465159

51475160
// These hold register type information for the whole of target.xml.
51485161
// target.xml may include further documents that
@@ -5159,7 +5172,11 @@ bool ProcessGDBRemote::GetGDBServerRegisterInfo(ArchSpec &arch_to_use) {
51595172
!registers.empty())
51605173
AddRemoteRegisters(registers, arch_to_use);
51615174

5162-
return m_register_info_sp->GetNumRegisters() > 0;
5175+
return m_register_info_sp->GetNumRegisters() > 0
5176+
? llvm::ErrorSuccess()
5177+
: llvm::createStringError(
5178+
llvm::inconvertibleErrorCode(),
5179+
"the debug server did not describe any registers");
51635180
}
51645181

51655182
llvm::Expected<LoadedModuleInfoList> ProcessGDBRemote::GetLoadedModuleList() {

lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,7 @@ class ProcessGDBRemote : public Process,
416416
void AddRemoteRegisters(std::vector<DynamicRegisterInfo::Register> &registers,
417417
const ArchSpec &arch_to_use);
418418
// Query remote GDBServer for register information
419-
bool GetGDBServerRegisterInfo(ArchSpec &arch);
419+
llvm::Error GetGDBServerRegisterInfo(ArchSpec &arch);
420420

421421
lldb::ModuleSP LoadModuleAtAddress(const FileSpec &file,
422422
lldb::addr_t link_map,

0 commit comments

Comments
 (0)