c9 / core

Cloud9 Core - Part of the Cloud9 SDK for Plugin Development https://c9.github.io/core/ https://c9.io
Other
2.56k stars 921 forks source link

fixed argument parsing in gdb shim #460

Closed kzidane closed 7 years ago

kzidane commented 7 years ago

The state machine that removes array labels is buggy. It can mistakenly confuse arrays and JSON objects with values containing special characters (e.g., [, {, etc).

Sample program:

#include <stdio.h>

int main(void) {
    printf("[");
}

Reproducing steps:

(In a CS50 workspace)

  1. compile the program with -g
  2. break on the printf
  3. run debug50 <executable> where <executable> is the name of the executable
  4. once it breaks, try stepping into printf and that should result in a JSON-parsing error

In this case gdb outputs the following when stepping into printf:

reason="end-stepping-range",
frame={
    addr="0x00007ffff6ae7340",
    func="__printf",
    args=[
        {
            name="format",
            value="0x432592 \"[\""
        }
    ],
    file="printf.c",
    fullname="/build/eglibc-oGUzwX/eglibc-2.19/stdio-common/printf.c",
    line="28"
},
thread-id="1",
stopped-threads="all",
core="2"

in particular, the [ in value="0x432592 \"[\"" is confused with beginning of array which causes all characters 'til the first = to be set to ' ' and therefore breaking the JSON:

{
    "reason": "end-stepping-range",
    "frame": {
        "addr": "0x00007ffff6ae2340",
        "func": "__printf",
        "args": [
            {
                "name": "format",
                "value": "0x4325a2 \"[\""
            }
        ],       
       "printf.c",           
       "/build/eglibc-SvCtMH/eglibc-2.19/stdio-common/printf.c",
       "28"
    },
    "thread-id": "1",
    "stopped-threads": "all",
    "core": "2"
}

@nightwing this depends on gdb-mi-parser. We were wondering if we should add as an installer or install and add to the repo directly?

CC @crossroads1112 @dmalan @danallan

nightwing commented 7 years ago

Right now there is no good way for installing gdb-mi-parser, using installer has many issues, with checking for updates, and prompting the user every time something is updated. A better approach is to use a packager to automatically put all the required files into one, but until that is ready i think the next best thing is to just put contents of https://github.com/llop/gdb-mi-parser/blob/master/index.js into shim.js

kzidane commented 7 years ago

@nightwing added per 4d00440.