-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[Tools] Create swift-inspect, a debugging tool for dumping Swift runtime data from another process #31468
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@mikeash what does dt stand for? Maybe it would make sense to expand out the name? My thought: swift_memory_dumping_tool? |
@@ -191,8 +191,8 @@ void mangleIdentifier(Mangler &M, StringRef ident) { | |||
// of the identifier - that's why we added the dummy-word). | |||
// The first thing: we add the encoded sub-string length. | |||
M.Buffer << (Repl.StringPos - Pos); | |||
assert(!isDigit(ident[Pos]) && | |||
"first char of sub-string may not be a digit"); | |||
// assert(!isDigit(ident[Pos]) && |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missed this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks. I'm fixing this up along with some other stuff. Not quite done with it yet!
@gottesmm It stands for Swift Debug Tool. There's some internal precedent with other |
@mikeash does it debug everything about a swift program? To me debug tool is very generic to the point of being confusing = /. |
it stands for debug/dump tool |
"swiftrtdt" for Swift runtime debug tool? |
tools/swiftdt/main.swift
Outdated
} | ||
|
||
if let commandName = commandName { | ||
print("error: \(executableName): unknown command \(commandName)", to: &Std.err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can these both be argFail() calls?
tools/swiftdt/main.swift
Outdated
} | ||
|
||
let commandName = argv.popFirst() | ||
for command in commands { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Check that argv is now empty here, or else allow multiple commands to be run in one execution.
@MadCoder I figured as much. I was just pointing out the ambiguity of the name. |
@gparker42 I think swift runtime debug tool would be a better name. At least it is clear what you are debugging. |
tools/swiftdt/CMakeLists.txt
Outdated
@@ -0,0 +1,14 @@ | |||
add_swift_target_executable(swiftdt |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the wrong way to do this. We do not want add_swift_target_executable to be used outside of the stdlib directory. This is in preparation for splitting the stdlib from the main host build.
If you need to be in swift's cmake build, I would suggest putting this tool into ./stdlib/tools.
Otherwise, if you can compile against a just built toolchain, I would create a build-script tool that builds against the just built toolchain.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I imagine that you can do the latter since you are just using remote mirrors.
tools/swiftdt/main.swift
Outdated
} | ||
|
||
func printUsage(args: inout ArraySlice<String>) { | ||
print("Usage: \(executableName) <command>", to: &Std.err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
print("Usage: \(executableName) <pid | process name> <command>", to: &Std.err)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@gottesmm helped me transform this into a proper package, so I went ahead and redid it to use ArgumentParser
instead of rolling my own. Now we get all the right behavior for free!
@mikeash one cool thing is that if you make this a build-script tool, you can use the swift package manager and get access to the argument parser/other things. |
*use the just built swiftpm with your project. |
@mikeash #31667. I tested that locally. It works. If one wants to invoke the build_script_helper.py directly, one does it like this:
Or to do it using build-script normally:
|
d516251
to
ca1add9
Compare
This comment has been minimized.
This comment has been minimized.
nameOrPid: String | ||
) -> (Inspector, SwiftReflectionContextRef) { | ||
guard let pid = pidFromHint(nameOrPid) else { | ||
argFail("Cannot find pid/process \(nameOrPid)") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you don’t mind making this a throwing method, you can use ValidationError
here.
argFail("Cannot find pid/process \(nameOrPid)") | |
throw ValidationError("Cannot find pid/process \(nameOrPid)") |
…e in another process. rdar://problem/55481578
…symbols from libswiftCore. rdar://problem/55481578
…mbols and read the contents of Conformances. rdar://problem/55481578
rdar://problem/55481578
rdar://problem/55481578
…running. rdar://problem/55481578
rdar://problem/55481578
@swift-ci please test |
Build failed |
Build failed |
@swift-ci please test os x platform |
Build failed |
@swift-ci please test os x platform |
Build failed |
@swift-ci please test |
Build failed |
Build failed |
@swift-ci please test |
Build failed |
Build failed |
@swift-ci please test |
Build failed |
Build failed |
@swift-ci please test |
Build failed |
Build failed |
@swift-ci please test |
Build failed |
@swift-ci please test Linux platform |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Create
swift-inspect
. This is a tool which can inspect a Swift process and dump information about the Swift runtime in that process.It currently supports inspecting two kinds of information:
It's meant to grow more functionality over time.
The design of the tool places all of the runtime-related smarts in Remote Mirror.
swiftdt
is then a small that connects the Remote Mirror functionality with remote process inspection. The remote process inspection parts are necessarily OS-specific. Currently they're only implemented for Apple OSes. Everything is cleanly separated out so that someone who knows the appropriate APIs for another OS should be able to add support for that OS without much difficulty.Update: after much soul searching, we have renamed this from
swiftdt
toswift-inspect
, which is more descriptive and better fits the naming conventions of other tools.