-
Notifications
You must be signed in to change notification settings - Fork 15.4k
[lldb] Improve logging of failure to get register information from Target XML #170478
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…rget XML 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.
|
@llvm/pr-subscribers-lldb Author: David Spickett (DavidSpickett) ChangesIn 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. Full diff: https://github.com/llvm/llvm-project/pull/170478.diff 2 Files Affected:
diff --git a/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp b/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
index 3c4d9a1f1ad37..6f45095c28977 100644
--- a/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
+++ b/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
@@ -441,8 +441,16 @@ void ProcessGDBRemote::BuildDynamicRegisterInfo(bool force) {
if (!arch_to_use.IsValid())
arch_to_use = target_arch;
- if (GetGDBServerRegisterInfo(arch_to_use))
+ llvm::Error register_info_err = GetGDBServerRegisterInfo(arch_to_use);
+ if (!register_info_err) {
+ // We got the registers from target XML.
return;
+ }
+
+ Log *log = GetLog(GDBRLog::Process);
+ LLDB_LOG_ERROR(log, std::move(register_info_err),
+ "Failed to read register information from target XML: {0}");
+ LLDB_LOG(log, "Now trying to use qRegisterInfo instead.");
char packet[128];
std::vector<DynamicRegisterInfo::Register> registers;
@@ -5137,14 +5145,19 @@ void ProcessGDBRemote::AddRemoteRegisters(
// query the target of gdb-remote for extended target information returns
// true on success (got register definitions), false on failure (did not).
-bool ProcessGDBRemote::GetGDBServerRegisterInfo(ArchSpec &arch_to_use) {
- // Make sure LLDB has an XML parser it can use first
- if (!XMLDocument::XMLEnabled())
- return false;
-
- // check that we have extended feature read support
+llvm::Error ProcessGDBRemote::GetGDBServerRegisterInfo(ArchSpec &arch_to_use) {
+ // If the remote does not offer XML, does not matter if we would have been
+ // able to parse it.
if (!m_gdb_comm.GetQXferFeaturesReadSupported())
- return false;
+ return llvm::createStringError(
+ llvm::inconvertibleErrorCode(),
+ "The debug server does not support \"qXfer:features:read\"");
+
+ if (!XMLDocument::XMLEnabled())
+ return llvm::createStringError(
+ llvm::inconvertibleErrorCode(),
+ "The debug server supports \"qXfer:features:read\", but LLDB does not "
+ "have XML enabled (check LLLDB_ENABLE_LIBXML2)");
// These hold register type information for the whole of target.xml.
// target.xml may include further documents that
@@ -5161,7 +5174,11 @@ bool ProcessGDBRemote::GetGDBServerRegisterInfo(ArchSpec &arch_to_use) {
!registers.empty())
AddRemoteRegisters(registers, arch_to_use);
- return m_register_info_sp->GetNumRegisters() > 0;
+ return m_register_info_sp->GetNumRegisters() > 0
+ ? llvm::ErrorSuccess()
+ : llvm::createStringError(
+ llvm::inconvertibleErrorCode(),
+ "Debug server did not describe any registers");
}
llvm::Expected<LoadedModuleInfoList> ProcessGDBRemote::GetLoadedModuleList() {
diff --git a/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.h b/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.h
index eb33b52b57441..b7e8777c9e12e 100644
--- a/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.h
+++ b/lldb/source/Plugins/Process/gdb-remote/ProcessGDBRemote.h
@@ -416,7 +416,7 @@ class ProcessGDBRemote : public Process,
void AddRemoteRegisters(std::vector<DynamicRegisterInfo::Register> ®isters,
const ArchSpec &arch_to_use);
// Query remote GDBServer for register information
- bool GetGDBServerRegisterInfo(ArchSpec &arch);
+ llvm::Error GetGDBServerRegisterInfo(ArchSpec &arch);
lldb::ModuleSP LoadModuleAtAddress(const FileSpec &file,
lldb::addr_t link_map,
|
|
Some things I'm not sure on:
|
|
Also it would be cool if there was some discoverable way to check for XML support. GCC has an option that prints what it was configured with, and if you had a packaged llvm release, maybe you could find it in the cmake files. Otherwise, I don't think we have one. Other than finding a command that happens to ingest XML but I think they're all JSON or other niche formats. |
We have |
I would personally prefer this option. If we're worried about it being to spammy, we could also scope it to the debugger or have a static so it's printed only once per LLDB instance. Both are kinda hacky though. Another option is to make it configurable with a setting and including the setting in the warning. The "stepping through optimized code" is another very spammy one that I've been meaning to make configurable.
Given that the log is primarily intended for us as LLDB developers, I don't have any concerns with mentioning the CMake option. |
|
I was wondering what exactly would happen (swiftlang/swift#85345) to thanks for figuring that out and making the status quo better! |
Yes that would be great. Being able to see curl/python/lua/etc. settings would be a big help too. |
I know there was work done for FreeBSD server debugging so that LLDB correctly assumes the register offsets without needing XML information. Which their server stub, I presume, does not send. In user space they'd be using lldb-server so qRegisterInfo should convey the same information the XML would have. |
I will do this for a follow up change. Once per session makes sense, if you're reconnecting over and over, you probably don't care about the warning enough to want to see it again. |
|
I've filed #170727 and should have a PR for this shortly. |
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