summaryrefslogtreecommitdiff
path: root/.config/nyxt/objdump.lisp
diff options
context:
space:
mode:
authorThanos Apollo <[email protected]>2023-09-27 02:10:25 +0300
committerThanos Apollo <[email protected]>2023-09-27 02:10:25 +0300
commit47b73144d1b30514df003560851de3bd06e88b81 (patch)
tree27b0b2e914c6867d90f6ce456b123606803a8a09 /.config/nyxt/objdump.lisp
parent696a16039e28e5844a164d69f60006b9c11a0067 (diff)
[New] Add nyxt, slightly modified config from aartaka
Diffstat (limited to '.config/nyxt/objdump.lisp')
-rw-r--r--.config/nyxt/objdump.lisp52
1 files changed, 52 insertions, 0 deletions
diff --git a/.config/nyxt/objdump.lisp b/.config/nyxt/objdump.lisp
new file mode 100644
index 0000000..341e2ce
--- /dev/null
+++ b/.config/nyxt/objdump.lisp
@@ -0,0 +1,52 @@
+(in-package #:nyxt-user)
+
+(define-internal-page-command-global objdump (&key (file (uiop:native-namestring
+ (prompt1 :prompt "File to disassemble"
+ :input (uiop:native-namestring (uiop:getcwd))
+ :sources 'nyxt/mode/file-manager:file-source))))
+ (buffer (format nil "Objdump of ~a" file))
+ "Show disassembly of code sections and contents of data sections in FILE."
+ (spinneret:with-html-string
+ (let* ((disassembly
+ (uiop:run-program (list "objdump" "--demangle" "--debugging" "--disassemble"
+ "--line-numbers" "--source" "--visualize-jumps" "--wide" file)
+ :output '(:string :stripped t)))
+ (lines (member-if (lambda (elem) (uiop:string-prefix-p "Disassembly" elem))
+ (mapcar #'str:trim (str:split "
+
+" disassembly :omit-nulls t))))
+ (sections (mapcar
+ (lambda (string)
+ (multiple-value-bind (start end starts ends)
+ (ppcre:scan "(\\d+)\\s*([^\\s]*).*" string)
+ (subseq string (elt starts 1) (elt ends 1))))
+ (remove-if-not
+ (lambda (str) (digit-char-p (elt str 0)))
+ (remove-if #'uiop:emptyp
+ (mapcar #'str:trim
+ (serapeum:lines
+ (uiop:run-program (list "objdump" "-h" file)
+ :output '(:string :stripped t))))))))
+ (code-sections (loop for (section code) on lines by #'cddr
+ collect (if (uiop:string-prefix-p "Disassembly of section " section)
+ (serapeum:slice section 23 -1)
+ section)))
+ (data-sections (set-difference sections code-sections :test #'string-equal)))
+ (loop for (section code) on lines by #'cddr
+ collect (:nsection
+ :id (prini-to-string (new-id))
+ :title (if (uiop:string-prefix-p "Disassembly of section " section)
+ (subseq section 23)
+ section)
+ (:pre code)))
+ (loop for data in data-sections
+ collect (:nsection
+ :id (prini-to-string (new-id))
+ :title data
+ (:pre (cadr (mapcar
+ #'str:trim
+ (str:split "
+
+" (uiop:run-program (list "objdump" "--section" data "--full-contents" file)
+ :output '(:string :stripped t))
+:omit-nulls t)))))))))