From 03f82561a619985e36349767d5dfbfd600e10325 Mon Sep 17 00:00:00 2001 From: Chad Smith Date: Wed, 4 Jan 2017 17:09:52 -0800 Subject: [PATCH 1/7] saving wip --- gdbgui/static/js/gdbgui.js | 63 +++++++++++++++++++++++++++--------- gdbgui/templates/gdbgui.jade | 15 +++++++++ 2 files changed, 62 insertions(+), 16 deletions(-) diff --git a/gdbgui/static/js/gdbgui.js b/gdbgui/static/js/gdbgui.js index ad657687..dc46d496 100644 --- a/gdbgui/static/js/gdbgui.js +++ b/gdbgui/static/js/gdbgui.js @@ -288,8 +288,13 @@ const Breakpoint = { links.push(`View`) } links.push(`remove`) - bkpt[' '] = links.join(' | ') + + // turn address into link + if (bkpt['addr']){ + bkpt['addr'] = Memory.make_addr_into_link(bkpt['addr']) + } + // add the breakpoint if it's not stored already if(Breakpoint.breakpoints.indexOf(bkpt) === -1){ Breakpoint.breakpoints.push(bkpt) @@ -508,7 +513,7 @@ const Disassembly = { } } for(let i of asm_insns){ - let assembly = i['line_asm_insn'].map(el => `${el['func-name']}+${el['offset']} ${el.address} ${el.inst}`) + let assembly = i['line_asm_insn'].map(el => `${el['func-name']}+${el['offset']} ${Memory.make_addr_into_link(el.address)} ${el.inst}`) let line_link = `${i.line} view` let source_line = '(file not loaded)' if(i.line <= source_code.length){ @@ -528,6 +533,9 @@ const Stack = { if ('fullname' in s){ s[' '] = `View` } + if ('addr' in s){ + s.addr = Memory.make_addr_into_link(s.addr) + } } let [columns, data] = Util.get_table_data_from_objs(stack) @@ -653,6 +661,25 @@ const GdbCommandInput = { } } +const Memory = { + el: $('#memory'), + init: function(){ + $("body").on("click", ".memory_address", Memory.click_memory_address) + }, + click_memory_address: function(e){ + let addr = e.currentTarget.dataset['memory_address'] + GdbApi.run_gdb_command(` -data-read-memory-bytes ${addr} 1`) + }, + render_memory: function(mi_memory_data){ + let data = mi_memory_data.map(m => _.values(m)) + let table = Util.get_table(_.keys(mi_memory_data[0]), data) + Memory.el.html(table) + }, + make_addr_into_link: function(addr){ + return `${addr}` + } +} + const GlobalEvents = { // Initialize init: function(){ @@ -698,28 +725,31 @@ const process_gdb_response = function(response_array){ Breakpoint.store_breakpoint(r.payload.bkpt) Breakpoint.render_breakpoint_table() SourceCode.fetch_and_render_file(r.payload.bkpt.fullname, r.payload.bkpt.line, {'highlight': false, 'scroll': true}) - - } else if ('BreakpointTable' in r.payload){ + } + if ('BreakpointTable' in r.payload){ Breakpoint.assign_breakpoints_from_mi_breakpoint_table(r.payload) SourceCode.rerender() - - } else if ('stack' in r.payload) { + } + if ('stack' in r.payload) { Stack.render_stack(r.payload.stack) - - } else if ('register-names' in r.payload) { + } + if ('register-names' in r.payload) { Registers.set_register_names(r.payload['register-names']) - - } else if ('register-values' in r.payload) { + } + if ('register-values' in r.payload) { Registers.render_registers(r.payload['register-values']) - - } else if ('asm_insns' in r.payload) { + } + if ('asm_insns' in r.payload) { Disassembly.render_disasembly(r.payload.asm_insns) - - } else if ('files' in r.payload){ + } + if ('files' in r.payload){ SourceFileAutocomplete.input.list = _.uniq(r.payload.files.map(f => f.fullname)).sort() SourceFileAutocomplete.input.evaluate() - - } // else if (your check here) { + } + if ('memory' in r.payload){ + Memory.render_memory(r.payload.memory) + } + // if (your check here) { // render your custom compenent here! // } @@ -772,6 +802,7 @@ SourceCode.init() Disassembly.init() BinaryLoader.init() SourceFileAutocomplete.init() +Memory.init() window.addEventListener("beforeunload", BinaryLoader.onclose) diff --git a/gdbgui/templates/gdbgui.jade b/gdbgui/templates/gdbgui.jade index 23299e2f..7b0e47fd 100644 --- a/gdbgui/templates/gdbgui.jade +++ b/gdbgui/templates/gdbgui.jade @@ -134,6 +134,21 @@ body span.glyphicon.glyphicon-refresh.padding_left div#disassembly.gdb_content_div + div.col-md-6.no_padding + div.titlebar + span.lighttext variables + span.glyphicon.glyphicon-plus.resizer.pointer(data-target_selector="#variables" data-resize_type="enlarge") + span.glyphicon.glyphicon-minus.resizer.pointer(data-target_selector="#variables" data-resize_type="shrink") + div#variables.gdb_content_div + + div.col-md-6.no_padding + div.titlebar + span.lighttext memory + span.glyphicon.glyphicon-plus.resizer.pointer(data-target_selector="#memory" data-resize_type="enlarge") + span.glyphicon.glyphicon-minus.resizer.pointer(data-target_selector="#memory" data-resize_type="shrink") + div#memory.gdb_content_div + + div.col-md-6.no_padding div.titlebar span.lighttext gdb machine interface output From 8b7a0c1cbc65af12517156e905b5e864dcf38a2b Mon Sep 17 00:00:00 2001 From: Chad Smith Date: Thu, 5 Jan 2017 08:55:35 -0800 Subject: [PATCH 2/7] remember last binaries entered; update colors on gdb command input; watch more files for changes when reloading in debug mode --- gdbgui/backend.py | 12 +++++++----- gdbgui/static/css/gdbgui.css | 10 ++++++++++ gdbgui/static/js/gdbgui.js | 27 ++++++++++++++++++++++----- gdbgui/templates/gdbgui.jade | 12 ++++++++---- 4 files changed, 47 insertions(+), 14 deletions(-) diff --git a/gdbgui/backend.py b/gdbgui/backend.py index 82f0815b..df5ba60e 100755 --- a/gdbgui/backend.py +++ b/gdbgui/backend.py @@ -30,12 +30,14 @@ def client_error(obj): def get_extra_files(): + extra_dirs = [STATIC_DIR, TEMPLATE_DIR] extra_files = [] - for dirname, dirs, files in os.walk(TEMPLATE_DIR): - for filename in files: - filename = os.path.join(dirname, filename) - if os.path.isfile(filename): - extra_files.append(filename) + for extra_dir in extra_dirs: + for dirname, dirs, files in os.walk(extra_dir): + for filename in files: + filename = os.path.join(dirname, filename) + if os.path.isfile(filename): + extra_files.append(filename) return extra_files diff --git a/gdbgui/static/css/gdbgui.css b/gdbgui/static/css/gdbgui.css index 532557d7..605ead76 100644 --- a/gdbgui/static/css/gdbgui.css +++ b/gdbgui/static/css/gdbgui.css @@ -24,6 +24,16 @@ table{ color: #f9f9f9 !important; font-family: monospace !important; } +#gdb_command{ + padding-left: 45px; + border-top: 0; + border-top-left-radius: 0; + border-top-right-radius: 0; + font-size: 0.9em !important; + background-color: #3c3c3c !important; + color: #f9f9f9 !important; + font-family: monospace !important; +} #stdout { color: black; } diff --git a/gdbgui/static/js/gdbgui.js b/gdbgui/static/js/gdbgui.js index dc46d496..3e9de7dd 100644 --- a/gdbgui/static/js/gdbgui.js +++ b/gdbgui/static/js/gdbgui.js @@ -580,21 +580,24 @@ const Prefs = { const BinaryLoader = { el: $('#binary'), + el_past_binaries: $('#past_binaries'), init: function(){ // events $('#set_target_app').click(BinaryLoader.click_set_target_app) BinaryLoader.el.keydown(BinaryLoader.keydown_on_binary_input) try{ - BinaryLoader.last_binary = localStorage.getItem('last_binary') || '' - BinaryLoader.render(BinaryLoader.last_binary) + BinaryLoader.past_binaries = _.uniq(JSON.parse(localStorage.getItem('past_binaries'))) + BinaryLoader.render(BinaryLoader.past_binaries[0]) } catch(err){ - BinaryLoader.last_binary = '' + BinaryLoader.past_binaries = [] } - + // update list of old binarys + BinaryLoader.render_past_binary_options_datalist() }, + past_binaries: [], onclose: function(){ - localStorage.setItem('last_binary', BinaryLoader.el.val()) + localStorage.setItem('past_binaries', JSON.stringify(BinaryLoader.past_binaries) || []) return null }, click_set_target_app: function(e){ @@ -602,10 +605,18 @@ const BinaryLoader = { }, set_target_app: function(){ var binary_and_args = _.trim(BinaryLoader.el.val()) + if (binary_and_args === ''){ Status.render('enter a binary path before attempting to load') return } + + // save to list of binaries used that autopopulates the input dropdown + _.remove(BinaryLoader.past_binaries, i => i === binary_and_args) + BinaryLoader.past_binaries.unshift(binary_and_args) + BinaryLoader.render_past_binary_options_datalist() + + // find the binary and arguments so gdb can be told which is which let binary, args, cmds let index_of_first_space = binary_and_args.indexOf(' ') if( index_of_first_space === -1){ @@ -615,8 +626,11 @@ const BinaryLoader = { binary = binary_and_args.slice(0, index_of_first_space) args = binary_and_args.slice(index_of_first_space + 1, binary_and_args.length) } + + // tell gdb which arguments to use when calling the binary, before loading the binary cmds = [`-exec-arguments ${args}`, `-file-exec-and-symbols ${binary}`] + // reload breakpoints after sending to make sure they're up to date if (Prefs.auto_reload_breakpoints()){ cmds.push('-break-list') } @@ -631,6 +645,9 @@ const BinaryLoader = { BinaryLoader.set_target_app() } }, + render_past_binary_options_datalist: function(){ + BinaryLoader.el_past_binaries.html(BinaryLoader.past_binaries.map(b => `