Skip to content

Commit bd9030e

Browse files
authored
[debugserver] Move constants into TaskPortForProcessID (NFC) (llvm#166670)
I was looking at the calls to `usleep` in debugserver and noticed that these default arguments are never overwritten. I converted them to constants in the function, which makes it easier to reason about.
1 parent d2b43ff commit bd9030e

File tree

2 files changed

+7
-8
lines changed

2 files changed

+7
-8
lines changed

lldb/tools/debugserver/source/MacOSX/MachTask.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,7 @@ class MachTask {
8181
void TaskPortChanged(task_t task);
8282
task_t TaskPort() const { return m_task; }
8383
task_t TaskPortForProcessID(DNBError &err, bool force = false);
84-
static task_t TaskPortForProcessID(pid_t pid, DNBError &err,
85-
uint32_t num_retries = 10,
86-
uint32_t usec_interval = 10000);
84+
static task_t TaskPortForProcessID(pid_t pid, DNBError &err);
8785

8886
MachProcess *Process() { return m_process; }
8987
const MachProcess *Process() const { return m_process; }

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -523,14 +523,15 @@ static void get_threads_profile_data(DNBProfileDataScanType scanType,
523523
//----------------------------------------------------------------------
524524
// MachTask::TaskPortForProcessID
525525
//----------------------------------------------------------------------
526-
task_t MachTask::TaskPortForProcessID(pid_t pid, DNBError &err,
527-
uint32_t num_retries,
528-
uint32_t usec_interval) {
526+
task_t MachTask::TaskPortForProcessID(pid_t pid, DNBError &err) {
527+
static constexpr uint32_t k_num_retries = 10;
528+
static constexpr uint32_t k_usec_delay = 10000;
529+
529530
if (pid != INVALID_NUB_PROCESS) {
530531
DNBError err;
531532
mach_port_t task_self = mach_task_self();
532533
task_t task = TASK_NULL;
533-
for (uint32_t i = 0; i < num_retries; i++) {
534+
for (uint32_t i = 0; i < k_num_retries; i++) {
534535
DNBLog("[LaunchAttach] (%d) about to task_for_pid(%d)", getpid(), pid);
535536
err = ::task_for_pid(task_self, pid, &task);
536537

@@ -557,7 +558,7 @@ static void get_threads_profile_data(DNBProfileDataScanType scanType,
557558
}
558559

559560
// Sleep a bit and try again
560-
::usleep(usec_interval);
561+
::usleep(k_usec_delay);
561562
}
562563
}
563564
return TASK_NULL;

0 commit comments

Comments
 (0)