Commit Graph

524 Commits

Author SHA1 Message Date
Alex Light
92476657e3 gdbclient.py alternative frontend support
This adds a new --setup-forwarding {gdb|vscode} flag that will make
gdbclient.py (1) setup the port forwarding needed to connect to a
remote process and (2) print the commands/configuration needed to use
the frontend of your choice to run the debugger. Currently it supports
gdb and visual-studio code. In order to avoid using up all the ports
the gdbclient.py program will not exit until directed by user input,
holding the ports open until this occurs.

To use:

```
% ./development/scripts/gdbclient.py -n com.android.contacts --setup-forwarding vscode
Redirecting gdbserver output to /tmp/gdbclient.log

{
    "miDebuggerPath": "/fast-2/allight/aosp/prebuilts/gdb/linux-x86/bin/gdb",
    "program": "/fast-2/allight/aosp/out/target/product/walleye/symbols/system/bin/app_process64",
    "setupCommands": [
        {
            "text": "-enable-pretty-printing",
            "description": "Enable pretty-printing for gdb",
            "ignoreFailures": true
        },
        {
            "text": "-environment-directory /fast-2/allight/aosp",
            "description": "gdb command: dir",
            "ignoreFailures": false
        },
        {
            "text": "-gdb-set solib-search-path /fast-2/allight/aosp/out/target/product/walleye/symbols/system/lib64/:/fast-2/allight/aosp/out/target/product/walleye/symbols/system/lib64/hw:/fast-2/allight/aosp/out/target/product/walleye/symbols/system/lib64/ssl/engines:/fast-2/allight/aosp/out/target/product/walleye/symbols/system/lib64/drm:/fast-2/allight/aosp/out/target/product/walleye/symbols/system/lib64/egl:/fast-2/allight/aosp/out/target/product/walleye/symbols/system/lib64/soundfx:/fast-2/allight/aosp/out/target/product/walleye/symbols/vendor/lib64/:/fast-2/allight/aosp/out/target/product/walleye/symbols/vendor/lib64/hw:/fast-2/allight/aosp/out/target/product/walleye/symbols/vendor/lib64/egl",
            "description": "gdb command: set solib-search-path",
            "ignoreFailures": false
        },
        {
            "text": "-gdb-set solib-absolute-prefix /fast-2/allight/aosp/out/target/product/walleye/symbols",
            "description": "gdb command: set solib-absolute-prefix",
            "ignoreFailures": false
        },
        {
            "text": "-interpreter-exec console \"source /fast-2/allight/aosp/development/scripts/gdb/dalvik.gdb\"",
            "description": "gdb command: source art commands",
            "ignoreFailures": false
        }
    ],
    "name": "(gdbclient.py) Attach app_process64 (port: 5039)",
    "miDebuggerServerAddress": "localhost:5039",
    "request": "launch",
    "type": "cppdbg",
    "cwd": "/fast-2/allight/aosp",
    "MIMode": "gdb"
}

Paste the above json into .vscode/launch.json and start the debugger as
normal. Press enter in this terminal once debugging is finished to shutdown
the gdbserver and close all the ports.

Press enter to shutdown gdbserver
```

Or for gdb:

```
% ./development/scripts/gdbclient.py -n com.android.contacts --setup-forwarding gdb
Redirecting gdbserver output to /tmp/gdbclient.log

file '/fast-2/allight/aosp/out/target/product/walleye/symbols/system/bin/app_process64'
directory '/fast-2/allight/aosp'
set solib-absolute-prefix /fast-2/allight/aosp/out/target/product/walleye/symbols
set solib-search-path /fast-2/allight/aosp/out/target/product/walleye/symbols/system/lib64/:/fast-2/allight/aosp/out/target/product/walleye/symbols/system/lib64/hw:/fast-2/allight/aosp/out/target/product/walleye/symbols/system/lib64/ssl/engines:/fast-2/allight/aosp/out/target/product/walleye/symbols/system/lib64/drm:/fast-2/allight/aosp/out/target/product/walleye/symbols/system/lib64/egl:/fast-2/allight/aosp/out/target/product/walleye/symbols/system/lib64/soundfx:/fast-2/allight/aosp/out/target/product/walleye/symbols/vendor/lib64/:/fast-2/allight/aosp/out/target/product/walleye/symbols/vendor/lib64/hw:/fast-2/allight/aosp/out/target/product/walleye/symbols/vendor/lib64/egl
source /fast-2/allight/aosp/development/scripts/gdb/dalvik.gdb

python

def target_remote_with_retry(target, timeout_seconds):
  import time
  end_time = time.time() + timeout_seconds
  while True:
    try:
      gdb.execute("target extended-remote " + target)
      return True
    except gdb.error as e:
      time_left = end_time - time.time()
      if time_left < 0 or time_left > timeout_seconds:
        print("Error: unable to connect to device.")
        print(e)
        return False
      time.sleep(min(0.25, time_left))

target_remote_with_retry(':5039', 5)

end

Paste the above gdb commands into the gdb frontend to setup the gdbserver
connection. Press enter in this terminal once debugging is finished to
shutdown the gdbserver and close all the ports.

Press enter to shutdown gdbserver
```

Test: ./development/scripts/gdbclient.py -n com.android.contacts --setup-forwarding vscode
      Perform debugging.

Change-Id: Ifa105cfbb100c4ba872b85c1c609d49a4f194d8b
2019-01-18 11:03:03 -08:00
Peter Collingbourne
63bf1087eb gdbclient.py: Add --env flag.
This flag allows users to set environment variables when running
a binary.

Change-Id: I01e2729c372da2e231bda86accc805495dcfdc06
2018-12-19 20:52:38 -08:00
Andreas Gampe
fa383d4beb Merge changes I37eb4151,If40a376d,Ic43b5cc6,Iaa9f304c am: 82f245e9d6 am: 9983327446
am: 0eed66500c

Change-Id: I517aee98ea9f760e866e8ad87a5acea07725e3ee
2018-10-30 14:54:32 -07:00
Andreas Gampe
e547eb3c9b Symbol: Add presubmit testing
Add symbol's unit tests to presubmit.

Test: atest python-symbol_test
Change-Id: I37eb4151365507ab2a95d7789408504cca78153c
2018-10-30 11:03:17 -07:00
Andreas Gampe
3ee240c6c3 NativeHeapDumpViewer: Add tests to presubmit
Add native_heapdump_viewer_tests to presubmit.

Test: atest python-native_heapdump_viewer_test
Change-Id: If40a376d160e774ef357d9ba2a86b40f6f7d05f0
2018-10-30 11:03:17 -07:00
Andreas Gampe
547631e12a NativeHeapDumpViewer: Python 3 compatibility
Fix some minor compat issues. Also clean up file close.

Test: native_heapdump_viewer_tests
Change-Id: Ic43b5cc61f26dd11fffe4e9b7a06056e4ed1c676
2018-10-30 11:03:17 -07:00
Andreas Gampe
9240b454cc Symbol: Python 3 compatibility
Fix some minor issues.

Test: symbol test
Change-Id: Iaa9f304c079abfc26212de8213fba38f4e311ec1
2018-10-30 11:03:17 -07:00
Mathieu Chartier
a44d913994 Merge "Prevent "index out of range" crash when addr2line aborts in between" am: 076bd27d03 am: f4b0e44285
am: 5dc39fb5a9

Change-Id: I2d890efcd38c3c7835d2eccb24265f226ac846f9
2018-10-09 10:28:22 -07:00
Mathieu Chartier
076bd27d03 Merge "Prevent "index out of range" crash when addr2line aborts in between" 2018-10-09 17:04:08 +00:00
Shibin George
7e73f7a7b4 Prevent "index out of range" crash when addr2line aborts in between
addr2line may abort and "result" may be incomplete. This leads to
"index out of range" exceptions. Enclose this in a try & except block
and on exception, default to function:location = ---:---

Test: "python native_heapdump_viewer_tests.py" (after CL:780974)
      passes.

BUG: 117306194

Change-Id: I4fd5c784949f279550aec95b68045df4a671da74
2018-10-09 06:21:03 +05:30
Shibin George
76962e13a0 Merge "native_heapdump_viewer_tests: update ParseNativeHeap() to pass 4 arguments" am: 3a5c7924a3 am: 89fc7d5d8e
am: b9f002bec8

Change-Id: If83045b7ce6f96e14a6e51722f26d7fb260321bc
2018-10-08 10:51:34 -07:00
Shibin George
b971e043f7 native_heapdump_viewer_tests: update ParseNativeHeap() to pass 4 arguments
fca3084 introduced an additional argument to ParseNativeHeap().
This CL updates the test to reflect the same.

Test: "python native_heapdump_viewer_tests.py" executes without
      any errors.

Change-Id: I6c196205ead2cb6abd4a646a3ac53e62ae3e5038
2018-10-06 03:54:13 +00:00
Joel Fernandes
9d51f4473f Merge "Remove ashmem from development repository" am: 9198f40364 am: 4ad8753727
am: 6ca70da806

Change-Id: I05030e1b2e78b4c6f453363163ae0e06740e6474
2018-08-30 13:21:03 -07:00
Joel Fernandes
ec9ee7f412 Remove ashmem from development repository
This topic removes ashmem from ART. Changes the names in development/
too. It only affects "dalvik-" ashmem regions which are the majority.

Change-Id: I1186eb60087384847892f655bec8174169ffd6c4
Signed-off-by: Joel Fernandes <joelaf@google.com>
2018-08-24 12:37:52 -07:00
Christopher Ferris
8731493c3f Merge "Handle IOExceptions if addr2line fails." am: 9a192cd10b am: 636042a889 am: 7d17c32a1a
am: 225a3c7448

Change-Id: If51cebc2b8187ef1fbe894db5ae22d4f36c091fe
2018-08-10 18:43:54 -07:00
Christopher Ferris
6fc7aefbba Handle IOExceptions if addr2line fails.
Bug: 112357697

Test: Verified that this doesn't cause any issues with a stack.
Test: Faked an exception and verified no crash.
Change-Id: I61982dbd44ac4f52b008bc35bbff2d9687f6ae25
2018-08-10 12:17:51 -07:00
Mathieu Chartier
76e11769f5 Merge "Fix GetMappingFromOffset" am: 0d2f6425ed am: 9e068aa334 am: 31a466e8f6
am: d5e817a29c

Change-Id: I5c28caeeb7f9aa80672caf509c456b1f897214e2
2018-08-03 17:29:24 -07:00
Mathieu Chartier
9e068aa334 Merge "Fix GetMappingFromOffset"
am: 0d2f6425ed

Change-Id: Ib743d58a691dbbe517f7cb4cf3ce37f7ce70000d
2018-08-03 16:34:36 -07:00
Mathieu Chartier
e3503620cd Fix GetMappingFromOffset
Fixed backward calculation of mapping offset.

Added logic to page align the data offset for uncompressed shared
objects. This fixes symbolization.

Bug: 111268230
Test: inspect native heap dump for the Camera app
Change-Id: If1af41e7265f017c1a691008309c8a002d5f588e
2018-08-03 13:26:10 -07:00
Mathieu Chartier
79a4d778f6 Merge "Add logic for replacing maps for zip files"
am: a70bf347f7

Change-Id: Icad4d96f4e083e472b59702e8b801d0e0eb4c1ff
2018-07-31 16:36:07 -07:00
Mathieu Chartier
fca30841f3 Add logic for replacing maps for zip files
For zip files, try to open the file in the current directory and
insert the files as mappings. This enables the script to pick up
embedded .so files.

Added a check to look in current directory before the symbol dir.

Added --app-symbols option to specify the directory containing the
app APK and so files.

Test: manual
Bug: 111268230

(cherry picked from commit b284c20247)

Merged-In: Id1b1f13bac78911daa6a72c35ebfadfdc9c1700f
Change-Id: Ia8d3dd64f16e1d06d929b4023292cb98a438ea3e
2018-07-31 14:24:29 -07:00
Mathieu Chartier
b284c20247 Add logic for replacing maps for zip files
For zip files, try to open the file in the current directory and
insert the files as mappings. This enables the script to pick up
embedded .so files.

Added a check to look in current directory before the symbol dir.

Added --app-symbols option to specify the directory containing the
app APK and so files.

Test: manual
Bug: 111268230
Change-Id: Id1b1f13bac78911daa6a72c35ebfadfdc9c1700f
2018-07-31 13:12:01 -07:00
Josh Gao
739452b7dd Merge "pid: switch to pgrep." am: 3aa9457410 am: 3140c7e495 am: e7e7d31b2b
am: 8ca04cddb5

Change-Id: I5e442229320fda316887c0896af7ee94f20a7f76
2018-07-23 19:14:39 -07:00
Josh Gao
3140c7e495 Merge "pid: switch to pgrep."
am: 3aa9457410

Change-Id: Ie2cbb889773651c922095a7fa7ae983c8431b1d8
2018-07-23 19:00:14 -07:00
Josh Gao
f080bf1f76 pid: switch to pgrep.
Fix a bug where processes that didn't have a leading space from right
justification of the pid column would return the process name instead
of the pid, by switching to pgrep.

Bug: http://b/111748205
Test: manual
Change-Id: I3493474540ccfa89f5bb3e66153d9e96ec8bf1d9
2018-07-23 17:01:42 -07:00
Christopher Ferris
626140143c Merge "Refactor native heap viewer to add tests." am: cd2f1cfed2 am: 9669de4c9e
am: 3cce3c1df9

Change-Id: I63befd4926b3a7d25cb8086ca67eeecacc0ae7cf
2018-07-16 14:42:21 -07:00
Christopher Ferris
9669de4c9e Merge "Refactor native heap viewer to add tests."
am: cd2f1cfed2

Change-Id: I6580a7d9624f27647f727889efb88f6e24ee0075
2018-07-16 14:28:04 -07:00
Christopher Ferris
dfb5368b57 Refactor native heap viewer to add tests.
This only includes a few tests to start with.

Bug: 62492960

Test: Ran new unit tests.
Test: Ran with all different options and verified it produces the same
Test: output as the previous script.
Change-Id: Iad29a5f04f49986139c92030a3259cae512859af
2018-07-13 14:09:43 -07:00
Christopher Ferris
81052a3c85 Merge "Detect if num field is valid on v1.0 version."
am: 1ae3edd54b

Change-Id: Ie14c18b08b3c8f9079c44645fe1ddb533e439d7b
2018-07-10 14:22:07 -07:00
Christopher Ferris
ad7d5fb378 Detect if num field is valid on v1.0 version.
In Android P, the version field did not get incremented properly in
all places. So if a file with a v1.0 version is found, do a further check
to verify if the num field is really valid.

Test: Verified that a file with v1.0 gets checked and the valid num field
Test: is set correctly.
Test: Verified that a file with v1.1 automatically gets num field set to
Test: valid.
Change-Id: I7f828294c833e334cad76a866bbaa1d78ac02cfb
Merged-In: I7f828294c833e334cad76a866bbaa1d78ac02cfb
(cherry picked from commit b558fe4d53)
2018-07-10 12:25:33 -07:00
Christopher Ferris
062202eb39 Merge "Detect if num field is valid on v1.0 version." 2018-07-10 19:24:46 +00:00
Christopher Ferris
b558fe4d53 Detect if num field is valid on v1.0 version.
In Android P, the version field did not get incremented properly in
all places. So if a file with a v1.0 version is found, do a further check
to verify if the num field is really valid.

Test: Verified that a file with v1.0 gets checked and the valid num field
Test: is set correctly.
Test: Verified that a file with v1.1 automatically gets num field set to
Test: valid.
Change-Id: I7f828294c833e334cad76a866bbaa1d78ac02cfb
2018-07-09 14:50:21 -07:00
Makoto Onuki
c22d8af0be Remove stacktrace in favor of "stacks"
Test: remove only
Bug: 110088132

Change-Id: I5c4f23066b21ff9621bbc32a1ae51421646c50c2
2018-07-02 13:44:31 -07:00
Dan Albert
dfecd4fc6d Merge "Allow restart in gdbclient." am: 2e4640f468 am: 590650db07
am: 90f910a7bd

Change-Id: I25f32ff880982274908cdc19d1ab5456e721b8fe
2018-06-26 13:30:44 -07:00
Dan Albert
590650db07 Merge "Allow restart in gdbclient."
am: 2e4640f468

Change-Id: I8440c29f0432284a925afa0d6d5748c49bdd4296
2018-06-26 13:22:50 -07:00
Dan Albert
d124bc7562 Allow restart in gdbclient.
Switching from remote to extended-remote allows the program being
debugged to be restarted like a normal non-remote program.

Test: Used gdbclient debugging ICU things for a while, restarted often
Bug: None
Change-Id: Ia295749b9aa86727479d760d7c743f98a06fa6d4
2018-06-26 11:15:16 -07:00
Josh Gao
f9459ad7b7 Merge changes from topic "stacks_envsetup" am: 759a6f75ff am: 121c8d9024
am: 49cec92cc6

Change-Id: I0881fabdb7252d63a01c3e8774d992a9bc1c9b5c
2018-06-15 09:06:57 -07:00
Josh Gao
7002fc1c03 Add return code support to pid. am: 4df6279c71 am: 3502ceecff
am: d8f3eb7759

Change-Id: I5391eb55691abfb2cebdf0b308113195385f57ae
2018-06-15 09:06:33 -07:00
Josh Gao
5ad6a81313 Move pid, stacks from envsetup.sh to dedicated scripts. am: 3dffb8438d am: aa32b1aaa9
am: df5e4326df

Change-Id: Idbe36816efd4f68263c6152329e84c6ae16914a6
2018-06-15 09:06:13 -07:00
Josh Gao
121c8d9024 Merge changes from topic "stacks_envsetup"
am: 759a6f75ff

Change-Id: I42facf6b00b039e37d62706bde4498117e90ec3f
2018-06-15 08:52:34 -07:00
Josh Gao
3502ceecff Add return code support to pid.
am: 4df6279c71

Change-Id: Ic853345ab244c6848349a99ec732f3b6c9ef87d8
2018-06-15 08:51:58 -07:00
Josh Gao
aa32b1aaa9 Move pid, stacks from envsetup.sh to dedicated scripts.
am: 3dffb8438d

Change-Id: I10024d4978f276286cc6e0e92722c5fc7e62c678
2018-06-15 08:51:21 -07:00
Treehugger Robot
759a6f75ff Merge changes from topic "stacks_envsetup"
* changes:
  stacks: match exactly before matching nonexactly.
  Add return code support to `pid`.
  Move pid, stacks from envsetup.sh to dedicated scripts.
2018-06-15 15:43:37 +00:00
Josh Gao
4df6279c71 Add return code support to pid.
Test: pid nonexistent; echo $?
Test: pid --exact nonexistent; echo $?
Change-Id: If8efb1ca27ae3ed7b5be1c51179fae387c56e305
2018-06-14 16:36:12 -07:00
Josh Gao
3dffb8438d Move pid, stacks from envsetup.sh to dedicated scripts.
Make it so that these can be used in other scripts by moving them from
functions defined in envsetup.sh to standalone scripts.

Test: stacks zygote64
Change-Id: I55ba76b248c54d9193fb019b7f4aca2f4c3a05bd
2018-06-14 16:36:12 -07:00
Josh Gao
91ba53c4b9 stacks: match exactly before matching nonexactly.
`pid zygote` will match zygote64 as well, but someone using `stacks
zygote` clearly wants the 32-bit version. Attempt an exact match before
we try a nonexact one.

Test: stacks zygote
Test: stacks zygote64
Change-Id: I5fd75cdbe4982c7ea831749c9ba823a2451e5490
2018-06-14 16:36:12 -07:00
Makoto Onuki
28af7e71ca Merge "Add some hostside scripts to make life easier" 2018-06-14 21:00:50 +00:00
Makoto Onuki
5cd3d2c9f0 Add some hostside scripts to make life easier
- Take a heapdump and open it with ahat on the browser:
runhat2 PID_OR_PROCESS_NAME

- Take thread stacktrace dump
stacktrace PID_OR_PROCESS_NAME

TODO: Remove runhat? Is there anyone still using it?

Bug: 110088132
Test: stacktrace system_server
Test: stacktrace $(pid system_server)
Test: stacktrace com.android.systemui
Test: runhat2 system_server
Change-Id: I8ee4b51ac9097d5342d2d4209407a4b8ac4d5945
2018-06-14 11:08:33 -07:00
Andreas Gampe
a5a9763fdb Merge "Script: Fix disassemble_tombstone.py"
am: 9a2f49a71a

Change-Id: I26497e24d245eb0c035b9807bab34c7873abde6b
2018-06-14 08:38:26 -07:00
Andreas Gampe
64676442d4 Script: Fix disassemble_tombstone.py
Update for newer debuggerd output marking the memory dump around
the currently executed code.

Add a hack for ARM assembly: override the assembler-emitted $d
symbol marking all our .byte data, so that objdump will disassemble
as instructions.

Test: manual
Change-Id: I100ed9e0ce39c073d5885cc430d78c24fef38882
2018-06-13 14:32:54 -07:00