Coder Social home page Coder Social logo

facebookarchive / ds2 Goto Github PK

View Code? Open in Web Editor NEW
242.0 32.0 74.0 96.68 MB

Debug server for lldb.

Home Page: https://github.com/facebook/ds2

License: Other

CMake 1.99% C++ 92.45% C 1.54% Shell 1.74% Batchfile 0.06% Yacc 0.19% Lex 0.15% Python 1.58% Dockerfile 0.31%
c-plus-plus toolchain lldb debugger

ds2's Introduction

ds2 Travis Build Status CircleCI AppVeyor Build Status Coverage Status

ds2 is a debug server designed to be used with LLDB to perform remote debugging of Linux, Android, FreeBSD, Windows and Windows Phone targets. Windows/Windows Phone support is still under active development.

Running ds2

Example

On the remote host

Launch ds2 with something like:

$ ./ds2 gdbserver localhost:4242 /path/to/TestSimpleOutput

ds2 is now ready to accept connections on port 4242 from lldb.

On your local host

$ lldb /path/to/TestSimpleOutput
Current executable set to '/path/to/TestSimpleOutput' (x86_64).
(lldb) gdb-remote localhost:4242
Process 8336 stopped
* thread #1: tid = 8336, 0x00007ffff7ddb2d0, name = 'TestSimpleOutput', stop reason = signal SIGTRAP
    frame #0: 0x00007ffff7ddb2d0
-> 0x7ffff7ddb2d0:  movq   %rsp, %rdi
   0x7ffff7ddb2d3:  callq  0x7ffff7ddea70
   0x7ffff7ddb2d8:  movq   %rax, %r12
   0x7ffff7ddb2db:  movl   0x221b17(%rip), %eax
(lldb) b main
Breakpoint 1: where = TestSimpleOutput`main + 29 at TestSimpleOutput.cpp:6, address = 0x000000000040096d
[... debug debug ...]
(lldb) c
Process 8336 resuming
Process 8336 exited with status = 0 (0x00000000)
(lldb)

Command-Line Options

ds2 accepts the following options:

usage: ds2 [RUN_MODE] [OPTIONS] [[HOST]:PORT] [-- PROGRAM [ARGUMENTS...]]
  -a, --attach ARG           attach to the name or PID specified
  -f, --daemonize            detach and become a daemon
  -d, --debug                enable debug log output
  -F, --fd ARG               use a file descriptor to communicate
  -g, --gdb-compat           force ds2 to run in gdb compat mode
  -o, --log-file ARG         output log messages to the file specified
  -N, --named-pipe ARG       determine a port dynamically and write back to FIFO
  -n, --no-colors            disable colored output
  -D, --remote-debug         enable log for remote protocol packets
  -R, --reverse-connect      connect back to the debugger at [HOST]:PORT
  -e, --set-env ARG...       add an element to the environment before launch
  -S, --setsid               make ds2 run in its own session
  -E, --unset-env ARG...     remove an element from the environment before lauch
  -l, --listen ARG           specify the [host]:port to listen on
  [host]:port                the [host]:port to connect to

After building ds2 for your target, run it with the binary to debug, or attach to an already running process. Then, start LLDB as usual and attach to the ds2 instance with the gdb-remote command.

The run mode and port number must be specified, where run mode is either g[dbserver] or p[latform]. In most cases, the g[dbserver] option is desired.

Building ds2

ds2 uses CMake to generate its build system. A variety of CMake toolchain files are provided to help with cross compilation for other targets.

Requirements

ds2 needs cmake, a C++11 compiler, flex and bison.

Compiling on Linux, FreeBSD and macOS

After cloning the ds2 repository, run the following commands to build for the current host:

cd ds2
mkdir build && cd build
cmake ..
make

Compiling on Windows

ds2 builds on Windows using Visual Studio. You'll need:

  • Windows builds of CMake for which you can grab binaries here;
  • flex and bison binaries -- easiest way to get these is to install them with Cygwin and add that to your PATH (usually C:\cygwin\bin);
  • an install of Visual Studio -- we use VS2015, but VS2013 should work too.

Then, as with linux, use CMake to generate the build system, then use msbuild (or the script provided) to build the binary:

cd ds2
mkdir build && cd build
cmake ..
..\Support\Scripts\build-windows.bat

Cross compiling for Windows Phone

ds2 can be built for Windows Phone, which will generate a dll that can later be loaded in by the application we are debugging as a separate process. This needs Visual Studio 2015.

To build for Windows Phone, use the Toolchain-WinStore.cmake toolchain file as well as the "Visual Studio 14 2015 ARM" CMake generator.

cd ds2
mkdir build && cd build
cmake -G "Visual Studio 14 2015 ARM" -DCMAKE_TOOLCHAIN_FILE=../Support/CMake/Toolchain-WinStore.cmake" ..
..\Support\Scripts\build-windows.bat

Cross compiling for Android

For Android native debugging, it is possible to build ds2 with the Android NDK. A script is provided to download the Android NDK automatically for you.

Support/Scripts/prepare-android-ndk.py will download a working version of the NDK, extract it, and install it to /tmp/android-ndk.

cd ds2
./Support/Scripts/prepare-android-ndk.py
mkdir build && cd build
cmake -DCMAKE_TOOLCHAIN_FILE=../Support/CMake/Toolchain-Android-ARM.cmake ..
make

Note that this will build ds2 targeting the highest level API level that the NDK supports. If you want to target another api level, e.g. 21, add the flag -DCMAKE_SYSTEM_VERSION=21 to your cmake invocation.

Testing on Android device

If you would like to use ds2 to run tests in the LLDB test suite using an Android device, you should use the script Support/Scripts/prepare-android-ndk.py to get a checkout of the android NDK. The LLDB test suite expects an NDK to exist on your host, and that script will download and unpack it where the CMake Toolchain files expect it to be.

Cross compiling for Linux-ARM

Cross-compiling for Linux-ARM is also possible. On Ubuntu 14.04, install an arm toolchain (for instance g++-4.8-arm-linux-gnueabihf) and use the provided toolchain file.

cd ds2
mkdir build && cd build
cmake -DCMAKE_TOOLCHAIN_FILE=../Support/CMake/Toolchain-Linux-ARM.cmake ..
make

This will generate a binary that you can copy to your device to start debugging.

Join the ds2 community

See the CONTRIBUTING.md file for how to help out.

License

ds2 is licensed under the University of Illinois/NCSA Open Source License.

We also provide an additional patent grant which can be found in the PATENTS file in the root directory of this source tree.

regsgen2, a tool used to generate register definitions is also licensed under the University of Illinois/NCSA Open Source License and uses a json library licensed under the Boost Software License. A complete copy of the latter can be found in Tools/libjson/LICENSE_1_0.txt.

ds2's People

Contributors

3on avatar andrewsb avatar bertmaher avatar bhamodi avatar bulbazord avatar cclauss avatar compnerd avatar emaste avatar fjricci avatar flarnie avatar kokarez avatar lanza avatar leofanyp avatar marksantaniello avatar mattmacumber avatar sas avatar shaoyuzhang avatar smeenai avatar suo avatar therealgymmy avatar tritao avatar vharrong avatar vjeux avatar walter-erquinigo avatar wataash avatar woody17 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ds2's Issues

On Windows, the thread stop status is always T00.

This should be T05 sometimes, to indicate voluntary stops from the debugger or the debug server. One of the side effects of this is that when we start the process, we don't have a stop reason so lldb doesn't display assembly at the entry point.

Move to Ubuntu 14.04 on travis.

12.04 is old, and that's gonna make our life easier, also it helps for getting away from the old infra I think (move to docker based).

x86 aliased registers (ax, al, ah and friends) read the wrong sub-words on Windows.

See the following output (grabbed with register read -a on lldb); ax is 0x0054 when it should be 0x0ee8 (lower 16 bits instead of higher 16 bits).

General Purpose Registers:
       eax = 0x00540ee8
       ebx = 0x00000000
       ecx = 0x00000001
       edx = 0x00450200
       esi = 0x00000001
       edi = 0x00000000
       ebp = 0x0028ff40
       esp = 0x0028feec
       eip = 0x0040362c  TestCppStreams.exe`main + 28 at main.c:297
    eflags = 0x00000210
        cs = 0x00000023
        ss = 0x0000002b
        ds = 0x0000002b
        es = 0x0000002b
        fs = 0x00000053
        gs = 0x0000002b
        ax = 0x0054
        bx = 0x0000
        cx = 0x0000
        dx = 0x0045
        si = 0x0000
        di = 0x0000
        bp = 0x0028
        sp = 0x0028
        ah = 0x54
        bh = 0x00
        ch = 0x00
        dh = 0x45
        al = 0x00
        bl = 0x00
        cl = 0x00
        dl = 0x00

Add travis targets to build with clang.

We only build with gcc on all our travis targets. We should have some clang targets as well, to make sure we are compatible, and to benefit from the added warnings this compiler gives sometimes.

Separate remote protocol logs from debug logs.

Right now, running ds2 with the -R options enables both debug logs, as well as remote protocol packet dumps. We should separate these two. Ideally, we'd have something like -R that dumps the remote protocol packets, and -d that enables debug logging.

Simplify the compatibility mode logic

We have a few different compatibility modes (LLDB, GDB, GDB with multiprocess, etc). It might be good to review these and make sure the logic there is not too complex.

Also, we need to decide whether we want to switch compat modes at run time based on packets received by the debugger or not. We already have command line options for that.

cross compiled ds2 not executable on nexus 4 / samsung galaxy s4

hey,
just played around a bit with your ds2. i would love to see it working!!!
nevertheless on my nexus 4 it's not working...

i cross compiled ds2 on ubuntu 14.04, which was a bit of a hurdle ( the tutorial you wrote should be extended and mention that you also have to install bison and flex as well... ). after cross compiling was working, i copied ds2 binary to /data/local/tmp

when i try to execute it i get following strange error message:

/system/bin/sh: ./ds2: No such file or directory

i verified that that ds2 is located at /data/local/tmp/ds2 and right are set correctly:

-rwxrwxrwx shell shell 1817889 2015-02-02 11:52 ds2

so either i'm missing something or there is some kind of problem here.

anyway, the project is great! keep on the good work.
looking forward to see a fix or help for my issue ;D

best regards,
mitp0sh

PS: Tested on a Samsung Galaxy S4 as well and have the same issue...

qXfer:features:read does not work.

qXfer:features:read seems buggy in ds2. When lldb requests register sets through this command, it doesn't seem to be able to properly read them afterwards.

This feature is disabled for now and lldb is able to query the list of registers by other mechanisms, which means debugging works fine. We should still fix this, as the qXfer based method is more efficient and uses a much smaller number of packets between server and client to achieve the same result.

To re-enable qXfer:features:read, look at Sources/GDBRemote/DebugSessionImpl.cpp:106 in the #if notyet block.

Implement jThreadsInfo.

This will be used to batch thread info on process stop; should improve performance greatly.
There doesn't seem to be any doc for this, we'll have to figure out what the code in lldb does instead.

Run MinGW builds on travis.

We're blocked on issue#115 for this, but once we're on 14.04, we can run MinGW builds, which will help maintain Windows builds in a decent state.

Fix onQueryProcessList

Right now, onQueryProcessList returns a list of all processes. It should only return the processes that match ProcessInfoMatch.

See the following functions:
PlatformSessionImpl::updateProcesses
Platform::EnumerateProcesses

Fix-Timeout.patch broke multi line output

Fix-Timeout use the table output as 1 entry per 1 stderr line read. When the process end, we call update_status.

    while True:
        line = process.stderr.readline()
        output.append(line)  # <-- line by line
        if line == '' and process.poll() is not None:
            break
        if 'PASS:' in line or 'FAIL:' in line:
            print '\r' + line,
            update_print(name)
        elif 'RESULT:' in line:
           output = [line]
     exit_status = process.returncode
     passes, failures = parse_test_results(output)
     update_status(name, command, output if exit_status != 0 else None)

The problem here is that update_status use the output table as the return of process.communicate, which mean the entry[0] is stdout and the entry[1] is stderr.

def update_status(name = None, command = None, output = None):
    global output_lock, test_counter, total_tests
    with output_lock:
        if output is not None:
            print >> sys.stderr
            print >> sys.stderr, "Failed test suite: %s" % name
            print >> sys.stderr, "Command invoked: %s" % ' '.join(command)
            print >> sys.stderr, "stdout:\n%s" % output[0]#  <-- stdout
            print >> sys.stderr, "stderr:\n%s" % output[1]#  <-- stderr
        sys.stderr.write("\r%*d out of %d test suites processed" %
            (len(str(total_tests)), test_counter.value, total_tests))
        test_counter.value += 1

realpath not installed when running on travis

On the last build log:

/home/travis/build/facebook/ds2/Support/Scripts/common.sh: line 49: realpath: command not found
/home/travis/build/facebook/ds2/Support/Scripts/common.sh: line 49: realpath: command not found

I've randomly pick 3 others build and found the same error.

Thread exit is not handled cleanly.

On Linux, when a thread exits, its placeholder stays active in LLDB longer than it should and ds2 logs a message stating it can't access /proc//status, which is gone because the thread just died.

Besides logging a message that makes little sense, the debug server functions properly. We should still try to have the correct behavior here.

Does not compile on freebsd 10.2

Following the instructions from Readme I got to the point when make says "fatal error: 'json_interanl.h' file not found. Looks like include paths and dependencies in CMake are not set correctly.

Simplify the StopInfo structure

StopReasons are a bit more complex than they should be. Main reason is because of the discrepancy in semantics between posix and windows systems.

CANNOT LINK EXECUTABLE: cannot locate symbol "posix_openpt" referenced by "ds2"...

device nexus5 with cm11,can't run.

ddmbp:android_build android$ make
[ 1%] [FLEX][JSON_SCANNER] Building scanner with flex 2.5.35
[ 3%] [BISON][JSON_PARSER] Building parser with bison 2.3
Scanning dependencies of target jsobjects
[ 5%] Building C object JSObjects/CMakeFiles/jsobjects.dir/parser.c.o
[ 6%] Building C object JSObjects/CMakeFiles/jsobjects.dir/tokenizer.c.o
[ 8%] Building CXX object JSObjects/CMakeFiles/jsobjects.dir/Sources/JSObjects.cpp.o
[ 10%] Building C object JSObjects/CMakeFiles/jsobjects.dir/Sources/libjson/json.c.o
[ 11%] Building C object JSObjects/CMakeFiles/jsobjects.dir/Sources/libjson/qstring.c.o
[ 13%] Linking CXX static library libjsobjects.a
[ 13%] Built target jsobjects
[ 15%] Building CXX object CMakeFiles/ds2.dir/Sources/Host/Common/Channel.cpp.o
[ 16%] Building CXX object CMakeFiles/ds2.dir/Sources/Host/Common/QueueChannel.cpp.o
[ 18%] Building CXX object CMakeFiles/ds2.dir/Sources/Host/Common/Socket.cpp.o
[ 20%] Building CXX object CMakeFiles/ds2.dir/Sources/Host/POSIX/File.cpp.o
[ 21%] Building CXX object CMakeFiles/ds2.dir/Sources/Host/POSIX/Platform.cpp.o
[ 23%] Building CXX object CMakeFiles/ds2.dir/Sources/Host/POSIX/PTrace.cpp.o
[ 25%] Building CXX object CMakeFiles/ds2.dir/Sources/Host/POSIX/ProcessSpawner.cpp.o
[ 26%] Building CXX object CMakeFiles/ds2.dir/Sources/Host/Linux/ProcFS.cpp.o
[ 28%] Building CXX object CMakeFiles/ds2.dir/Sources/Host/Linux/Platform.cpp.o
[ 30%] Building CXX object CMakeFiles/ds2.dir/Sources/Host/Linux/PTrace.cpp.o
[ 31%] Building CXX object CMakeFiles/ds2.dir/Sources/Host/Linux/ARM/PTraceARM.cpp.o
[ 33%] Building CXX object CMakeFiles/ds2.dir/Sources/Target/Common/ProcessBase.cpp.o
[ 35%] Building CXX object CMakeFiles/ds2.dir/Sources/Target/Common/ARM/ProcessBaseARM.cpp.o
[ 36%] Building CXX object CMakeFiles/ds2.dir/Sources/Target/Common/ThreadBase.cpp.o
[ 38%] Building CXX object CMakeFiles/ds2.dir/Sources/Target/POSIX/ELFProcess.cpp.o
[ 40%] Building CXX object CMakeFiles/ds2.dir/Sources/Target/POSIX/Process.cpp.o
[ 41%] Building CXX object CMakeFiles/ds2.dir/Sources/Target/POSIX/Thread.cpp.o
[ 43%] Building CXX object CMakeFiles/ds2.dir/Sources/Target/Linux/Process.cpp.o
[ 45%] Building CXX object CMakeFiles/ds2.dir/Sources/Target/Linux/ARM/ProcessARM.cpp.o
[ 46%] Building CXX object CMakeFiles/ds2.dir/Sources/Target/Linux/Thread.cpp.o
[ 48%] Building CXX object CMakeFiles/ds2.dir/Sources/Architecture/RegisterLayout.cpp.o
[ 50%] Building CXX object CMakeFiles/ds2.dir/Sources/Architecture/ARM/ARMBranchInfo.cpp.o
[ 51%] Building CXX object CMakeFiles/ds2.dir/Sources/Architecture/ARM/ThumbBranchInfo.cpp.o
[ 53%] Building CXX object CMakeFiles/ds2.dir/Sources/Architecture/ARM/HardwareBreakpointManager.cpp.o
[ 55%] Building CXX object CMakeFiles/ds2.dir/Sources/Architecture/ARM/SoftwareBreakpointManager.cpp.o
[ 56%] Building CXX object CMakeFiles/ds2.dir/Sources/Architecture/ARM/RegistersDescriptors.cpp.o
[ 58%] Building CXX object CMakeFiles/ds2.dir/Sources/Architecture/ARM/SoftwareSingleStep.cpp.o
[ 60%] Building CXX object CMakeFiles/ds2.dir/Sources/BreakpointManager.cpp.o
[ 61%] Building CXX object CMakeFiles/ds2.dir/Sources/CPUTypes.cpp.o
[ 63%] Building CXX object CMakeFiles/ds2.dir/Sources/ErrorCodes.cpp.o
[ 65%] Building CXX object CMakeFiles/ds2.dir/Sources/MessageQueue.cpp.o
[ 66%] Building CXX object CMakeFiles/ds2.dir/Sources/SessionThread.cpp.o
[ 68%] Building CXX object CMakeFiles/ds2.dir/Sources/Utils/Backtrace.cpp.o
[ 70%] Building CXX object CMakeFiles/ds2.dir/Sources/Utils/Log.cpp.o
[ 71%] Building CXX object CMakeFiles/ds2.dir/Sources/Utils/OptParse.cpp.o
[ 73%] Building CXX object CMakeFiles/ds2.dir/Sources/Utils/Paths.cpp.o
[ 75%] Building CXX object CMakeFiles/ds2.dir/Sources/Utils/Stringify.cpp.o
[ 76%] Building CXX object CMakeFiles/ds2.dir/Sources/main.cpp.o
[ 78%] Building CXX object CMakeFiles/ds2.dir/Sources/Support/POSIX/ELFSupport.cpp.o
[ 80%] Building CXX object CMakeFiles/ds2.dir/Sources/Utils/POSIX/FaultHandler.cpp.o
[ 81%] Building CXX object CMakeFiles/ds2.dir/Sources/Utils/POSIX/Stringify.cpp.o
[ 83%] Building CXX object CMakeFiles/ds2.dir/Sources/GDB/ByteCodeInterpreter.cpp.o
[ 85%] Building CXX object CMakeFiles/ds2.dir/Sources/GDBRemote/DebugSessionImpl.cpp.o
[ 86%] Building CXX object CMakeFiles/ds2.dir/Sources/GDBRemote/DummySessionDelegateImpl.cpp.o
[ 88%] Building CXX object CMakeFiles/ds2.dir/Sources/GDBRemote/PacketProcessor.cpp.o
[ 90%] Building CXX object CMakeFiles/ds2.dir/Sources/GDBRemote/PlatformSessionImpl.cpp.o
[ 91%] Building CXX object CMakeFiles/ds2.dir/Sources/GDBRemote/ProtocolInterpreter.cpp.o
[ 93%] Building CXX object CMakeFiles/ds2.dir/Sources/GDBRemote/Session.cpp.o
[ 95%] Building CXX object CMakeFiles/ds2.dir/Sources/GDBRemote/SessionBase.cpp.o
[ 96%] Building CXX object CMakeFiles/ds2.dir/Sources/GDBRemote/SlaveSessionImpl.cpp.o
[ 98%] Building CXX object CMakeFiles/ds2.dir/Sources/GDBRemote/Structures.cpp.o
[100%] Linking CXX executable ds2
[100%] Built target ds2
ddmbp:android_build android$ ./ds2
-bash: ./ds2: cannot execute binary file
ddmbp:android_build android$ file ./ds2
./ds2: ELF 32-bit LSB shared object, ARM, version 1 (SYSV), dynamically linked (uses shared libs), not stripped
ddmbp:android_build android$ adb shell
shell@hammerhead:/ $ ds2
126|root@hammerhead:/ # ds2
CANNOT LINK EXECUTABLE: cannot locate symbol "posix_openpt" referenced by "ds2"...
1|root@hammerhead:/ #

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.