Skip to content

Commit 2d15855

Browse files
authored
[lldb] [debugserver] address preprocessor warning, extra arg (#90808)
In DNBArchImplARM64.cpp I'm doing ``` #if __has_feature(ptrauth_calls) && defined(__LP64__) ``` And the preprocessor warns that this is not defined behavior. This checks if ptrauth_calls is available and if this is being compiled 64-bit (i.e. arm64e), and defines a single DEBUGSERVER_IS_ARM64E when those are both true. I did have to duplicate one DNBLogThreaded() call which itself is a macro, and using an ifdef in the middle of macro arguments also got me a warning from the preprocessor. While testing this for all the different targets, I found a DNBError initialization that accepts a c-string but I'm passing in a printf-style formatter c-string and an argument. Create the string before the call and pass in the constructed string. rdar://127129242
1 parent 9dca7dd commit 2d15855

File tree

2 files changed

+24
-21
lines changed

2 files changed

+24
-21
lines changed

lldb/tools/debugserver/source/MacOSX/MachProcess.mm

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4070,10 +4070,10 @@ static CFStringRef CopyBundleIDForPath(const char *app_bundle_path,
40704070
m_flags |= eMachProcessFlagsAttached;
40714071
DNBLog("[LaunchAttach] successfully attached to pid %d", m_pid);
40724072
} else {
4073-
launch_err.SetErrorString(
4074-
"Failed to attach to pid %d, BoardServiceLaunchForDebug() unable to "
4075-
"ptrace(PT_ATTACHEXC)",
4076-
m_pid);
4073+
std::string errmsg = "Failed to attach to pid ";
4074+
errmsg += std::to_string(m_pid);
4075+
errmsg += ", BoardServiceLaunchForDebug() unable to ptrace(PT_ATTACHEXC)";
4076+
launch_err.SetErrorString(errmsg.c_str());
40774077
SetState(eStateExited);
40784078
DNBLog("[LaunchAttach] END (%d) error: failed to attach to pid %d",
40794079
getpid(), m_pid);

lldb/tools/debugserver/source/MacOSX/arm64/DNBArchImplARM64.cpp

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,12 @@
2626
#include <cinttypes>
2727
#include <sys/sysctl.h>
2828

29+
#undef DEBUGSERVER_IS_ARM64E
2930
#if __has_feature(ptrauth_calls)
3031
#include <ptrauth.h>
32+
#if defined(__LP64__)
33+
#define DEBUGSERVER_IS_ARM64E 1
34+
#endif
3135
#endif
3236

3337
// Break only in privileged or user mode
@@ -115,7 +119,7 @@ static uint64_t clear_pac_bits(uint64_t value) {
115119
uint64_t DNBArchMachARM64::GetPC(uint64_t failValue) {
116120
// Get program counter
117121
if (GetGPRState(false) == KERN_SUCCESS)
118-
#if __has_feature(ptrauth_calls) && defined(__LP64__)
122+
#if defined(DEBUGSERVER_IS_ARM64E)
119123
return clear_pac_bits(
120124
reinterpret_cast<uint64_t>(m_state.context.gpr.__opaque_pc));
121125
#else
@@ -147,7 +151,7 @@ kern_return_t DNBArchMachARM64::SetPC(uint64_t value) {
147151
uint64_t DNBArchMachARM64::GetSP(uint64_t failValue) {
148152
// Get stack pointer
149153
if (GetGPRState(false) == KERN_SUCCESS)
150-
#if __has_feature(ptrauth_calls) && defined(__LP64__)
154+
#if defined(DEBUGSERVER_IS_ARM64E)
151155
return clear_pac_bits(
152156
reinterpret_cast<uint64_t>(m_state.context.gpr.__opaque_sp));
153157
#else
@@ -169,25 +173,24 @@ kern_return_t DNBArchMachARM64::GetGPRState(bool force) {
169173
(thread_state_t)&m_state.context.gpr, &count);
170174
if (DNBLogEnabledForAny(LOG_THREAD)) {
171175
uint64_t *x = &m_state.context.gpr.__x[0];
172-
DNBLogThreaded("thread_get_state signed regs "
173-
"\n fp=%16.16llx"
174-
"\n lr=%16.16llx"
175-
"\n sp=%16.16llx"
176-
"\n pc=%16.16llx",
177-
#if __has_feature(ptrauth_calls) && defined(__LP64__)
176+
177+
const char *log_str = "thread_get_state signed regs "
178+
"\n fp=%16.16llx"
179+
"\n lr=%16.16llx"
180+
"\n sp=%16.16llx"
181+
"\n pc=%16.16llx";
182+
#if defined(DEBUGSERVER_IS_ARM64E)
183+
DNBLogThreaded(log_str,
178184
reinterpret_cast<uint64_t>(m_state.context.gpr.__opaque_fp),
179185
reinterpret_cast<uint64_t>(m_state.context.gpr.__opaque_lr),
180186
reinterpret_cast<uint64_t>(m_state.context.gpr.__opaque_sp),
181-
reinterpret_cast<uint64_t>(m_state.context.gpr.__opaque_pc)
187+
reinterpret_cast<uint64_t>(m_state.context.gpr.__opaque_pc));
182188
#else
183-
m_state.context.gpr.__fp,
184-
m_state.context.gpr.__lr,
185-
m_state.context.gpr.__sp,
186-
m_state.context.gpr.__pc
189+
DNBLogThreaded(log_str, m_state.context.gpr.__fp, m_state.context.gpr.__lr,
190+
m_state.context.gpr.__sp, m_state.context.gpr.__pc);
187191
#endif
188-
);
189192

190-
#if __has_feature(ptrauth_calls) && defined(__LP64__)
193+
#if defined(DEBUGSERVER_IS_ARM64E)
191194
uint64_t log_fp = clear_pac_bits(
192195
reinterpret_cast<uint64_t>(m_state.context.gpr.__opaque_fp));
193196
uint64_t log_lr = clear_pac_bits(
@@ -661,7 +664,7 @@ kern_return_t DNBArchMachARM64::EnableHardwareSingleStep(bool enable) {
661664
return err.Status();
662665
}
663666

664-
#if __has_feature(ptrauth_calls) && defined(__LP64__)
667+
#if defined(DEBUGSERVER_IS_ARM64E)
665668
uint64_t pc = clear_pac_bits(
666669
reinterpret_cast<uint64_t>(m_state.context.gpr.__opaque_pc));
667670
#else
@@ -2187,7 +2190,7 @@ bool DNBArchMachARM64::GetRegisterValue(uint32_t set, uint32_t reg,
21872190
case e_regSetGPR:
21882191
if (reg <= gpr_pc) {
21892192
switch (reg) {
2190-
#if __has_feature(ptrauth_calls) && defined(__LP64__)
2193+
#if defined(DEBUGSERVER_IS_ARM64E)
21912194
case gpr_pc:
21922195
value->value.uint64 = clear_pac_bits(
21932196
reinterpret_cast<uint64_t>(m_state.context.gpr.__opaque_pc));

0 commit comments

Comments
 (0)