This is an archive of the discontinued LLVM Phabricator instance.

Implement -target-attach and -target-detach
ClosedPublic

Authored by ki.stfu on May 4 2015, 12:28 PM.

Details

Summary

This changes add -target-attach and -target-detach.

-target-attach allows lldb-mi to attach to an existing process by it's process id, matching gdb mi's syntax of '-target-attach <pid'. Additionally, support has been added for attaching to a process by name using '-target-attach -n <name>'. Combining this with --waitfor will allow lldb mi to attach to a process by name when the process starts.

-target-detach simply detaches from the current process

Patch from chuckr@microsoft.com

Diff Detail

Repository
rL LLVM

Event Timeline

ChuckR updated this revision to Diff 24905.May 4 2015, 12:28 PM
ChuckR retitled this revision from to Implement -target-attach and -target-detach.
ChuckR updated this object.
ChuckR edited the test plan for this revision. (Show Details)
ChuckR added reviewers: abidh, ki.stfu, paulmaybee.
ChuckR added a subscriber: Unknown Object (MLST).
ki.stfu accepted this revision.May 4 2015, 2:04 PM
ki.stfu edited edge metadata.

looks good

tools/lldb-mi/MICmdCmdTarget.h
66–68 ↗(On Diff #24905)

remove these lines

92 ↗(On Diff #24905)

add spacing

101–103 ↗(On Diff #24905)

remove these lines

This revision is now accepted and ready to land.May 4 2015, 2:04 PM
ChuckR updated this revision to Diff 24919.May 4 2015, 2:51 PM
ChuckR edited edge metadata.

Respond to Ilia K's feedback.

A few more comments. Please fix them before committing.

test/tools/lldb-mi/target/TestMiTarget.py
91 ↗(On Diff #24919)

New line

tools/lldb-mi/MICmdCmdTarget.cpp
322 ↗(On Diff #24919)

It isn't needed because GetProcess gets a process from current target. Please remove it and check that it still works.

abidh requested changes to this revision.May 5 2015, 2:02 AM
abidh edited edge metadata.
abidh added inline comments.
tools/lldb-mi/MICmdCmdTarget.cpp
255 ↗(On Diff #24919)

Remove commented lines

290 ↗(On Diff #24919)

Why are you putting this restriction? LLDB proper can find the symbols for executable it is attaching to (same as gdb). Also in GDB/MI, you can do -target-attach without first giving -file-exec-and-symbols.

432 ↗(On Diff #24919)

extra empty line.

tools/lldb-mi/MIExtensions.txt
53 ↗(On Diff #24919)

Please add a line telling which options are extra in lldb-mi. The line "The target must already be created with -file-exec-and-symbols." may need changing too based on my comment in -target-attach implementation.

This revision now requires changes to proceed.May 5 2015, 2:02 AM

Fyi.. All tests pass on OS X.

ChuckR updated this revision to Diff 24976.May 5 2015, 1:44 PM
ChuckR edited edge metadata.

I removed the requirement for -file-exec-and-symbols to be called before -target-attach. I was able to fix the tests for -target-attach <pid> and -target-attach -n <name>. I was able to get -target-attach -n <name> --waitfor to work in practice, but not through the python test without first issuing a -file-exec-and-symbols. Any help would be appreciated.

abidh added a comment.May 6 2015, 2:39 AM

Sorry I can not be much help here. This --waitfor option is not supported on Linux so I can not investigate it much. Also attaching to non-child process is not allowed on ubuntu generally.
https://wiki.ubuntu.com/SecurityTeam/Roadmap/KernelHardening#ptrace_Protection

So if don't really need the waitfor option, you can remove it from this patch. In any case, disable these tests for Linux untill we found a way to run them with above mentioned restriction.

With these changes, your patch should be ok to go in.

ChuckR updated this revision to Diff 25058.May 6 2015, 9:32 AM
ChuckR edited edge metadata.

I do need the --waitfor option. I am now skipping these tests on Linux.

ki.stfu accepted this revision.May 6 2015, 10:20 PM
ki.stfu edited edge metadata.

@ChuckR, I'll commit it for you right now.

ki.stfu commandeered this revision.May 7 2015, 12:30 AM
ki.stfu updated this object.
ki.stfu edited edge metadata.
ki.stfu edited reviewers, added: ChuckR; removed: ki.stfu.
ki.stfu updated this revision to Diff 25136.May 7 2015, 12:31 AM

Rebase against ToT

ki.stfu updated this revision to Diff 25137.May 7 2015, 12:36 AM

Expand tabs

ki.stfu updated this revision to Diff 25138.May 7 2015, 12:40 AM

Fix error handling in CMICmdCmdTargetAttach::Execute

This revision was automatically updated to reflect the committed changes.