Skip to content

Commit 0cf4f74

Browse files
authored
[linux] make lldb platform status properly report kernel version
## Purpose Make the lldb `platform status` command properly report the kernel version when connected to ds2 on a remote Linux or Android system. ## Overview * Rename `Platform::GetOSKernelPath` to `Platform::GetOSKernelVersion`. It was only implemented for Windows and was never called on that platform since Windows doesn't support platform mode. * Fix Linux `Platform::GetOSBuild` to return the `release` string returned by `uname(2)`. This behavior matches lldb-server behavior. * Implement Linux `Platform::GetOSKernelVersion` to return the `version` string returned from `uname(2). This behavior matches the lldb-server behavior. * Implement `Platform::GetOSKernelVersion` for Windows. There is currently no way to test this code since Windows ds2 doesn't support platform mode. I did this to match the fact that `GetOSKernelPath` was previously supported on Windows. * Leave `GetOSKernelVersion` unimplemented on Darwin and FreeBSD just like `GetOSKernelPath` had been previously. * Enable the lldb test that was failing due to missing kernel version in the `platform status` result. ## Problem Details In lldb, the `platform status` command lists details about the remote connection. On Linux and Android, it should report the kernel version but it currently does not when connected to ds2. The output of `platform status` when connected to ds2 on Android: ``` (lldb) platform status Platform: remote-android Triple: x86_64-unknown-linux-android OS Version: 34 (1) Hostname: localhost Connected: yes WorkingDir: /data/local/tmp ``` The output of `platform status` when connected to lldb-server: ``` (lldb) platform status Platform: remote-android Triple: x86_64-unknown-linux-android OS Version: 34 (6.1.23-android14-4-00257-g7e35917775b8-ab9964412) Hostname: localhost Connected: yes WorkingDir: /data/local/tmp Kernel: #1 SMP PREEMPT Mon Apr 17 20:50:58 UTC 2023 ``` Results for Linux are similar. ## Validation Verified the lldb test `TestPlatformCommand.PlatformCommandTestCase.test_status` now passes locally run against ds2 on Android and Linux. Manually inspected the output of the `platform status` command connected to ds2: On Android: ``` (lldb) platform status Platform: remote-android Triple: x86_64-unknown-linux-android OS Version: 34 (6.1.23-android14-4-00257-g7e35917775b8-ab9964412) Hostname: localhost Connected: yes WorkingDir: /data/local/tmp Kernel: #1 SMP PREEMPT Mon Apr 17 20:50:58 UTC 2023 ``` On Linux: ``` (lldb) platform status Platform: remote-linux Triple: x86_64-unknown-linux OS Version: 6.10.7 (6.10.7-200.fc40.x86_64) Hostname: placeholder Connected: yes WorkingDir: /home/andrew/src/ds2 Kernel: #1 SMP PREEMPT_DYNAMIC Fri Aug 30 00:08:59 UTC 2024 ``` This output exactly matches when calling `platform status` from lldb connected to lldb-server.
1 parent 6c26921 commit 0cf4f74

File tree

6 files changed

+15
-29
lines changed

6 files changed

+15
-29
lines changed

Headers/DebugServer2/Host/Platform.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class Platform {
4040
static char const *GetOSVendorName();
4141
static char const *GetOSVersion();
4242
static char const *GetOSBuild();
43-
static char const *GetOSKernelPath();
43+
static char const *GetOSKernelVersion();
4444

4545
public:
4646
static bool GetUserName(UserId const &uid, std::string &name);

Sources/GDBRemote/DummySessionDelegateImpl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ ErrorCode DummySessionDelegateImpl::onQueryHostInfo(Session &,
9898
info.osBuild = build;
9999
}
100100

101-
char const *kernel = Platform::GetOSKernelPath();
101+
char const *kernel = Platform::GetOSKernelVersion();
102102
if (kernel != nullptr) {
103103
info.osKernel = kernel;
104104
}

Sources/Host/Darwin/Platform.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ char const *Platform::GetOSVersion() {
9494

9595
char const *Platform::GetOSBuild() { return GetCachedUTSName()->version; }
9696

97-
char const *Platform::GetOSKernelPath() { return nullptr; }
97+
char const *Platform::GetOSKernelVersion() { return nullptr; }
9898

9999
const char *Platform::GetSelfExecutablePath() {
100100
return Host::Darwin::LibProc::GetExecutablePath(getpid());

Sources/Host/Linux/Platform.cpp

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -73,20 +73,9 @@ static struct utsname const *GetCachedUTSName() {
7373

7474
char const *Platform::GetOSVersion() { return GetCachedUTSName()->release; }
7575

76-
char const *Platform::GetOSBuild() {
77-
static char sBuild[32] = {'\0'};
78-
79-
if (sBuild[0] == '\0') {
80-
char const *version = GetCachedUTSName()->version;
81-
// Linux version is returned as #BUILDNO ...
82-
ds2::Utils::SNPrintf(sBuild, sizeof(sBuild), "%lu",
83-
std::strtoul(version + 1, nullptr, 10));
84-
}
85-
86-
return sBuild;
87-
}
76+
char const *Platform::GetOSBuild() { return GetCachedUTSName()->release; }
8877

89-
char const *Platform::GetOSKernelPath() { return nullptr; }
78+
char const *Platform::GetOSKernelVersion() { return GetCachedUTSName()->version; }
9079

9180
const char *Platform::GetSelfExecutablePath() {
9281
static char path[PATH_MAX + 1] = {'\0'};

Sources/Host/Windows/Platform.cpp

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -109,23 +109,21 @@ char const *Platform::GetOSBuild() {
109109
return buildStr;
110110
}
111111

112-
char const *Platform::GetOSKernelPath() {
113-
static std::string kernelPath;
112+
char const *Platform::GetOSKernelVersion() {
113+
static char versionStr[32] = {'\0'};
114114

115-
if (kernelPath.size() == 0) {
116-
WCHAR wideKernelPath[MAX_PATH];
117-
UINT rc;
115+
if (versionStr[0] == '\0') {
116+
OSVERSIONINFO version;
118117

119-
rc = ::GetWindowsDirectoryW(wideKernelPath, sizeof(wideKernelPath));
120-
if (rc == 0 || rc >= sizeof(wideKernelPath))
121-
goto error;
118+
version.dwOSVersionInfoSize = sizeof(version);
119+
if (!::GetVersionEx(&version))
120+
return versionStr;
122121

123-
kernelPath = ds2::Utils::WideToNarrowString(wideKernelPath);
124-
kernelPath.append("\\System32\\ntoskrnl.exe");
122+
ds2::Utils::SNPrintf(versionStr, sizeof(versionStr), "%lu.%lu",
123+
version.dwMajorVersion, version.dwMinorVersion);
125124
}
126125

127-
error:
128-
return kernelPath.c_str();
126+
return versionStr;
129127
}
130128

131129
bool Platform::GetUserName(UserId const &uid, std::string &name) {

Support/Testing/Excluded/ds2/android-x86_64.excluded

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ TestNonStop.LldbGdbServerTestCase.test_vCont_then_stop_llgs
4747
TestNonStop.LldbGdbServerTestCase.test_vCtrlC_llgs
4848
TestPartialResume.TestPartialResume.test_vCont_cxcx_llgs
4949
TestPartialResume.TestPartialResume.test_vCont_cxcxt_llgs
50-
TestPlatformCommand.PlatformCommandTestCase.test_status
5150
TestProcessAttach.ProcessAttachTestCase.test_attach_to_process_by_id
5251
TestProcessAttach.ProcessAttachTestCase.test_attach_to_process_by_id_autocontinue
5352
TestProcessAttach.ProcessAttachTestCase.test_attach_to_process_by_id_correct_executable_offset

0 commit comments

Comments
 (0)