Skip to content
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
b9083ea
add a process picker for attaching by PID
matthewbastien Feb 26, 2025
b423842
convert pid to a number so that lldb-dap can properly consume it
matthewbastien Feb 26, 2025
ee7b00e
update extension README
matthewbastien Feb 26, 2025
82ef750
allow matching on the full command line arguments in the process picker
matthewbastien Feb 26, 2025
f4407b2
use execFile() instead of spawn() to simplify logic
matthewbastien Feb 28, 2025
daf2618
use camel case for ${command:pickProcess}
matthewbastien Mar 6, 2025
b2c0382
allow filtering processes by program
matthewbastien Mar 6, 2025
18cba4b
fix Linux process tree to include the full executable path
matthewbastien Mar 6, 2025
85a19e4
minor fixes to Darwin process tree
matthewbastien Mar 6, 2025
f84f5cc
remove program property from attach to process ID example
matthewbastien Mar 6, 2025
0a615f2
add `lldb-dap.attachToProcess` command
matthewbastien Mar 6, 2025
6f40eb3
use Get-CimInstance on Windows because WMIC is deprecated
matthewbastien Mar 6, 2025
d4c81e1
update README with more info about the 'program' property
matthewbastien Mar 6, 2025
6deb671
add code comment to LinuxProcessTree's parser
matthewbastien Mar 6, 2025
582cd9b
use the pickProcess command in attach requests by default
matthewbastien Mar 7, 2025
548ac79
filter out zombie, trace, and debug state processes on macOS and Linux
matthewbastien Mar 7, 2025
f967f6d
allow searching by pid in the process picker
matthewbastien Mar 7, 2025
2492e1e
match program by basename like the docs say
matthewbastien Mar 7, 2025
e9b4e6a
use the process picker even if `program` is set
matthewbastien Mar 7, 2025
a18e5cc
update documentation for attaching to a process
matthewbastien Mar 7, 2025
55e0c95
update attach parameter table in the README
matthewbastien Mar 7, 2025
6d01d9a
show an error message if no program is provided for waitFor
matthewbastien Mar 7, 2025
e4155ec
update description of waitFor in the package.json to indicate that th…
matthewbastien Mar 7, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions lldb/tools/lldb-dap/src-ts/debug-configuration-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,23 @@ function convertToInteger(value: any): number | undefined {
export class LLDBDapConfigurationProvider
implements vscode.DebugConfigurationProvider
{
resolveDebugConfiguration(
_folder: vscode.WorkspaceFolder | undefined,
debugConfiguration: vscode.DebugConfiguration,
_token?: vscode.CancellationToken,
): vscode.ProviderResult<vscode.DebugConfiguration> {
// Default "pid" to ${command:pickProcess} if neither "pid" nor "program" are specified
// in an "attach" request.
if (
debugConfiguration.request === "attach" &&
!("pid" in debugConfiguration) &&
!("program" in debugConfiguration)
) {
debugConfiguration.pid = "${command:pickProcess}";
Copy link
Member

@vogelsgesang vogelsgesang Mar 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we mark pid as optional in the the package.json and the README.md?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've updated both of these to better reflect my changes. I did a pretty major overhaul of the README section on attaching and would appreciate another thorough review there to make sure the wording sounds good.

}
return debugConfiguration;
}

resolveDebugConfigurationWithSubstitutedVariables(
_folder: vscode.WorkspaceFolder | undefined,
debugConfiguration: vscode.DebugConfiguration,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export class DarwinProcessTree extends LinuxProcessTree {
return [
"-axo",
// The length of comm must be large enough or data will be truncated.
`pid=PID,lstart=START,comm=${"COMMAND".padEnd(256, "-")},args=ARGUMENTS`,
`pid=PID,state=STATE,lstart=START,comm=${"COMMAND".padEnd(256, "-")},args=ARGUMENTS`,
];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export class LinuxProcessTree extends BaseProcessTree {
return [
"-axo",
// The length of exe must be large enough or data will be truncated.
`pid=PID,lstart=START,exe:128=COMMAND,args=ARGUMENTS`,
`pid=PID,state=STATE,lstart=START,exe:128=COMMAND,args=ARGUMENTS`,
];
}

Expand All @@ -23,21 +23,30 @@ export class LinuxProcessTree extends BaseProcessTree {
return;
}

const pid = /^\s*([0-9]+)\s*/.exec(line);
if (!pid) {
const pidAndState = /^\s*([0-9]+)\s+([a-zA-Z<>+]+)\s+/.exec(line);
if (!pidAndState) {
return;
}

// Make sure the process isn't in a trace/debug or zombie state as we cannot attach to them
const state = pidAndState[2];
if (state.includes("X") || state.includes("Z")) {
return;
}

// ps will list "-" as the command if it does not know where the executable is located
const command = line.slice(commandOffset, argumentsOffset).trim();
if (command === "-") {
return;
}

return {
id: Number(pid[1]),
id: Number(pidAndState[1]),
command,
arguments: line.slice(argumentsOffset).trim(),
start: Date.parse(line.slice(pid[0].length, commandOffset).trim()),
start: Date.parse(
line.slice(pidAndState[0].length, commandOffset).trim(),
),
};
};
}
Expand Down