From b1431a047c86dd22a74cbd9de68c062058ad8eb4 Mon Sep 17 00:00:00 2001 From: Knorx Date: Wed, 24 Sep 2025 22:24:37 +0200 Subject: [PATCH 1/2] Added better assembly highlighting --- gdbgui/src/js/SourceCode.tsx | 49 +++++++++++++++++++++++++++++------- gdbgui/static/css/gdbgui.css | 18 ++++++++++--- 2 files changed, 55 insertions(+), 12 deletions(-) diff --git a/gdbgui/src/js/SourceCode.tsx b/gdbgui/src/js/SourceCode.tsx index 018c7fab..fc2eee8d 100644 --- a/gdbgui/src/js/SourceCode.tsx +++ b/gdbgui/src/js/SourceCode.tsx @@ -260,19 +260,50 @@ class SourceCode extends React.Component<{}, State> { ) : ( ); + const instStr: string = assm.inst || ""; + const [mnemonic, ...operandParts] = instStr.trim().split(/\s+/); + const operandsStr = operandParts.join(" "); + + // split operands by commas but keep commas + const operandTokens = operandsStr.split(/(\,)/).map((tok) => tok.trim()).filter((tok) => tok.length > 0); + + const highlightedOperands = operandTokens.map((tok, i) => { + if (/^\%[a-z0-9]+$/i.test(tok)) { + // register like %rax + return {tok}; + } else if (/^\$?0x[0-9a-f]+$/i.test(tok) || /^\$?\d+$/i.test(tok)) { + // immediate or numeric constant + return {tok}; + } else if (tok === ",") { + return {tok}; + } else { + // memory reference or other + return {tok}; + } + }); + + const highlightedInstruction = ( + <> + {mnemonic}{" "} + {highlightedOperands} + + ); return ( - - {/* @ts-expect-error ts-migrate(2769) FIXME: Property 'fontFamily' is missing in type '{ paddin... Remove this comment to see the full error message */} - {asterisk} - {opcodes /* i.e. mov */} - {instruction} + + {asterisk} + + {opcodes} + + {mnemonic} + + + {highlightedOperands} + {func_name ? ( - + {func_name}+{offset} - ) : ( - "" - )} + ) : ""} ); } diff --git a/gdbgui/static/css/gdbgui.css b/gdbgui/static/css/gdbgui.css index 71ec63f3..9be1b099 100644 --- a/gdbgui/static/css/gdbgui.css +++ b/gdbgui/static/css/gdbgui.css @@ -181,9 +181,21 @@ td.assembly { white-space: nowrap; } /* instruction content */ -.instrContent { - min-width: 250px; - display: inline-block; +.asm-mnemonic { + color: green; + font-weight: bold; +} +.asm-register { + color: red; +} +.asm-immediate { + color: #489ce4; +} +.asm-other { + color: inherit; /* leave neutral, or customize if you want memory refs distinct */ +} +.asm-address { + color: #489ce4; } #code_table { font-family: monospace; From f5550345480e736fbe182805db1c048766aaa29a Mon Sep 17 00:00:00 2001 From: Knorx Date: Wed, 24 Sep 2025 22:29:02 +0200 Subject: [PATCH 2/2] Update gdbgui.css --- gdbgui/static/css/gdbgui.css | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gdbgui/static/css/gdbgui.css b/gdbgui/static/css/gdbgui.css index 9be1b099..136c5c58 100644 --- a/gdbgui/static/css/gdbgui.css +++ b/gdbgui/static/css/gdbgui.css @@ -192,7 +192,7 @@ td.assembly { color: #489ce4; } .asm-other { - color: inherit; /* leave neutral, or customize if you want memory refs distinct */ + color: inherit; } .asm-address { color: #489ce4;