Commit Graph

140 Commits

Author SHA1 Message Date
Andrew Rogers
76c2719e47 Update tools/swift-inspect/Sources/swift-inspect/WindowsRemoteProcess.swift
Co-authored-by: Saleem Abdulrasool <compnerd@compnerd.org>
2024-12-11 16:01:18 -08:00
Andrew Rogers
f9db32c292 [swift-inspect] stop leaking memory in Windows heap iteration 2024-12-11 15:47:16 -08:00
Andrew Rogers
1ce1956d8a [swift-inspect] FreeLibrary returns 0 on failure not success 2024-12-11 15:30:30 -08:00
Andrew Rogers
3aef500131 formatting fixes and missed copyright date updates 2024-12-10 10:34:18 -08:00
Andrew Rogers
61f6b0e704 PR Feedback: make ProcFS an enum instead of a class 2024-12-05 09:57:57 -08:00
Andrew Rogers
f669299572 properly override the Free property in LinuxRemoteProcess 2024-12-05 09:57:46 -08:00
Andrew Rogers
278f90cf93 PR feedback: fix typo 2024-12-04 13:52:03 -08:00
Andrew Rogers
e702be9cdc PR feedback: rework error definitions 2024-12-04 13:50:34 -08:00
Andrew Rogers
6e466c44e1 minimize ELF parsing support to ELF64 only 2024-12-04 13:10:56 -08:00
Andrew Rogers
48cd587866 PR feedback: add Process.readRawString to get byte count in GetStringLengthFunction 2024-12-04 11:35:12 -08:00
Andrew Rogers
5a277d499d PR feedback: short-circuit return on readArray of 0 items 2024-12-04 11:23:32 -08:00
Andrew Rogers
671db08c1d PR feedback: use precondition in place of assert 2024-12-04 11:19:54 -08:00
Andrew Rogers
3b0e5bb160 consistent use of /proc 2024-12-04 11:19:25 -08:00
Andrew Rogers
9e5f0ca9cd PR feedback: update copyright to 2024 2024-12-04 11:00:37 -08:00
Andrew Rogers
aa6bfabf60 PR feedback: fix typo in README.md 2024-12-04 10:59:19 -08:00
Andrew Rogers
31460f63b8 specify -Xlinker instead of -Xswiftc in README.md 2024-12-03 20:01:14 -08:00
Andrew Rogers
6dc7c3265d address some code review comments 2024-12-03 17:15:02 -08:00
Andrew Rogers
4906ed9c36 [linux] define _GNU_SOURCE for process_vm_readv 2024-12-03 15:53:05 -08:00
Andrew Rogers
59d39a1c7d [linux] exclude dump-array support 2024-12-03 14:47:16 -08:00
Andrew Rogers
049af2e0e0 [linux] add Linux build instructions to README.txt 2024-12-03 14:47:16 -08:00
Andrew Rogers
2ee5d15886 [linux] swift-inspect support for Linux 2024-12-03 14:47:16 -08:00
Saleem Abdulrasool
bb3d3a59a7 Merge pull request #77724 from compnerd/inspection
swift-inspect: add initial CMake based build system
2024-11-20 21:14:23 -08:00
Saleem Abdulrasool
22a014b484 swift-inspect: add initial CMake based build system
This addition will allow us to cross-compile swift-inspect to Windows
ARM64. Enabling the Windows ARM64 build permits the toolchain to become
more similar across the architectures.
2024-11-19 15:41:52 -08:00
Saleem Abdulrasool
87b3d51c70 swift-inspect: remove obsolete workaround
`-fno-split-cold-code` should no longer be needed after
llvm/llvm-project#99759. Remove the use of unsafe flags.
2024-11-19 12:20:43 -08:00
Mike Ash
37dc7d5c66 [swift-inspect] Force forkCorpse if VMUProcInfo advises it.
Various processes, such as launchd, are unsafe to inspect directly. Inspecting them pauses them and the system does not like it when they're paused. Forking a corpse avoids this, as the original process continues running while we inspect the forked corpse.

VMUProcInfo provides a shouldAnalyzeWithCorpse call which tells us whether we're inspecting one of those processes. When we are, then we force the forkCorpse option even when it's not specified.

Add shims to Symbolication+Extensions.swift to allow calls to VMUProcInfo and use it to force forkCorpse when appropriate.

rdar://124720793
2024-10-22 12:27:11 -04:00
Ian Anderson
578336c859 Build fix for when the Darwin module is split up
After the C standard library headers are split out of Darwin, DumpConcurrency.swift no longer sees string.h. Explicitly import <string.h>'s new module when it's available.
rdar://127076885
2024-08-07 15:46:02 -07:00
Alexander Cyon
4a2942bb4e Fix typos in: cmake, tools, utils, unittests, validation-test
Co-authored-by: Saleem Abdulrasool <compnerd@compnerd.org>
2024-07-12 02:34:00 +03:00
Alex Hoppen
8e20a6f479 Update links for repositories moved to the swiftlang org on GitHub 2024-06-25 04:35:39 -07:00
Cassie Jones
f478b79af9 swift-inspect: Explicitly reference String.init(cString:)
This was briefly failing to build because of an ambiguous initializer
while making other changes, it's better to be explicit with method names
anyway.

rdar://127548384
2024-05-07 14:06:36 -07:00
Saleem Abdulrasool
18fa46021c Merge pull request #70103 from compnerd/remote
swift-inspect: clean up some of the code in `WindowsRemoteProcess`
2023-12-03 12:23:54 -08:00
Saleem Abdulrasool
7a6c6c7eee swift-inspect: clean up some of the code in WindowsRemoteProcess
Add some vertical whitespace to the code ejection process.  Alter the
logic to clean up the memory allocation first, ignoring the error as the
subsequent run will perform a new allocation and this will leak a fixed
amount of memory without interrupting the process or use of the tool.
No longer check the exit code of the thread as that is always guaranteed
to be 0 as the module unloading path does not report any error code in
the injected code (DLL).

Use the opportunity to do some simple renaming to improve the
readability and create an overload for avoiding unnecessary ceremony
around use of a shared constant.
2023-12-02 08:56:52 -08:00
Emre Celebi
6a2650371d [swift-inspect] Again: Fix integer type mismatch on watchOS build.
Redo Mike's changes which were reverted: Convert integers to to `swift_reflection_ptr_t` instead of `UInt64` since watchOS uses `UInt` as its pointer type.

rdar://118458631
2023-11-30 10:09:21 -08:00
Emre Celebi
0953b1d514 [swift-inspect] Deallocate symbolicator after inspecting a process
This change deallocates the symbolicator. Added CSRelease to symbolication
extensions.
2023-11-29 17:00:30 -08:00
Emre Celebi
2a3d3cb894 Merge pull request #69916 from w6sec/swift-inspect-json
[swift-inspect] Add JSON output option for dump-generic-metadata
2023-11-29 12:00:35 -08:00
Emre Celebi
4af03a89a2 [swift-inspect] Inspect all processes and add summary option
With this change swift-inspect can inspect all processes to see if metadata allocation iteration is enabled. We also added summary option that sorts metadata to popularity.
2023-11-29 07:19:04 -08:00
Emre Celebi
f0a6b02bb6 [swift-inspect] Change argument options to select between file or standard output
With this change we make --json flag to toggle between JSON and text output. If --output-file option is given, then the output stream is forwarded to the file specified.
2023-11-16 18:25:38 -08:00
Saleem Abdulrasool
d1459247d5 swift-inspect: clean up event creation on Windows
Create a Swiftier interface for `CreateEvent` from the Windows SDK and
use that to simplify the implementation of the remote process interface.
2023-11-16 12:27:01 -08:00
Emre Celebi
d9989d3e9f [swift-inspect] Add json output option for dump-generic-metadata
This change adds json output option to dump-generic-metadata for
swift-inspect.
2023-11-16 11:26:45 -08:00
Mike Ash
9477ed2626 [swift-inspect] Fix integer type mismatch on watchOS build.
Convert integers to to `swift_reflection_ptr_t` instead of `UInt64` since watchOS uses `UInt` as its pointer type.

rdar://118458631
2023-11-15 15:23:08 -05:00
YR Chen
be5a06555f Add support for SWIFTCI_USE_LOCAL_DEPS in swift-inspect
If the `SWIFTCI_USE_LOCAL_DEPS` environment variable is set, we're building in the Swift.org CI system alongside other projects in the Swift toolchain and we can depend on local versions of our dependencies instead of fetching them remotely.
2023-11-09 20:02:14 +08:00
Emre Celebi
b6f77a46be [swift-inspect] Add an option to print mangled names while dumping generic metadata. 2023-10-30 23:39:42 -07:00
Mike Ash
8689cf8a27 [swift-inspect] Compute ptrauth mask when building for plain ARM64.
This allows an ARM64 swift-inspect to correctly read from an ARM64e target process. We compute a ptrauth mask by stripping all bits above MACH_VM_MAX_ADDRESS. This strips more than we strictly need, but it works.
2023-10-23 15:53:49 -04:00
Mike Ash
7b32ffe601 [swift-inspect] Limit number of jobs printed on an actor.
If we encounter bad data in the target, we could end up trying to print an infinite list of jobs. Clamp it to 1,000 so we fail more gracefully.

rdar://113417637
2023-08-07 16:43:15 -04:00
Saleem Abdulrasool
72337efc3b build: adjust application of flags for LLVM issue (#67455)
The flags were meant to be applied to the C++ code not the Swift code.
Adjust the configuration to apply the flags properly.
2023-07-21 13:23:27 -07:00
Hiroshi Yamauchi
627175fe4c Fix a build issue with swift-inspect
Update the version of swift-argument-parser used by swift-inspect to
be compatible with the package description version.

Add compiler flags for a LLVM bug workaround.
2023-07-21 04:36:15 -07:00
Saleem Abdulrasool
bc9e90d318 swift-inspect: ensure that we eject any injected code
We would previously fail to eject the injected code on a failure.  This
would prevent a future introspection into the process as well as leave
the file open with an incremented retain count in the kernel space which
would prevent the file from being deleted.

In the future, when the application is able to treat the injected code
as a resource, this resource would be temporarily extracted, but would
no longer be possible to delete until a reboot (with a registration of
the deletion) due to the retained code.

Take the opportunity to rename some functions to take advantage of
labelled parameters and trailing function syntax.  This makes the code a
small amount easier to read.
2023-07-19 07:51:12 -07:00
Saleem Abdulrasool
255beb3d0e Merge pull request #67334 from compnerd/66973
swift-inspect: clean up incorrect casts introduced in #66973
2023-07-18 07:15:58 -07:00
Saleem Abdulrasool
c6fbff4c94 Merge pull request #67336 from compnerd/lambda-calculus
swift-inspect: correct some escaping binding for RemoteMirror
2023-07-18 07:15:35 -07:00
Saleem Abdulrasool
1b538f55ef swift-inspect: correct some escaping binding for RemoteMirror
Adjust the pointer handling for the callback and adjust the code to
ensure that we properly form memory references to the function for the
callback.
2023-07-17 10:58:18 -07:00
Saleem Abdulrasool
8794df84e9 swift-inspect: correct invalid memory usage introduced in #66973
Clean up the incorrect memory binding in swift-inspect introduced in
PR#66973.  This fixes the incorrect memory usage to mutate the `context`
parameter.
2023-07-17 10:16:26 -07:00