From 2dbd6808a5527b1945c98d2a5ee06fb022065b9c Mon Sep 17 00:00:00 2001 From: Dmitry Boulytchev Date: Tue, 8 Sep 2020 01:50:16 +0300 Subject: [PATCH] Better gdb support --- gdb/.gdbinit | 3 +++ src/Driver.ml | 6 ++++++ src/X86.ml | 12 ++++++------ src/version.ml | 2 +- 4 files changed, 16 insertions(+), 7 deletions(-) create mode 100644 gdb/.gdbinit diff --git a/gdb/.gdbinit b/gdb/.gdbinit new file mode 100644 index 000000000..ac345fc9f --- /dev/null +++ b/gdb/.gdbinit @@ -0,0 +1,3 @@ +define pp + p (char*) Bstringval ((void*) $arg0) +end diff --git a/src/Driver.ml b/src/Driver.ml index e1d1dc1ee..771ab15b6 100644 --- a/src/Driver.ml +++ b/src/Driver.ml @@ -66,6 +66,7 @@ class options args = val paths = ref [X86.get_std_path ()] val mode = ref (`Default : [`Default | `Eval | `SM | `Compile ]) val curdir = Unix.getcwd () + val debug = ref false (* Workaround until Ostap starts to memoize properly *) val const = ref false (* end of the workaround *) @@ -87,6 +88,7 @@ class options args = | "-dp" -> self#set_dump dump_ast | "-h" -> self#set_help | "-v" -> self#set_version + | "-g" -> self#set_debug | _ -> if opt.[0] = '-' then raise (Commandline_error (Printf.sprintf "Invalid command line specifier ('%s')" opt)) @@ -171,6 +173,10 @@ class options args = ); if !version then Printf.printf "%s\n" Version.version; if !help then Printf.printf "%s" help_string + method get_debug = + if !debug then "" else "-g" + method set_debug = + debug := true end let main = diff --git a/src/X86.ml b/src/X86.ml index 6027fe4ae..4ead5e8f1 100644 --- a/src/X86.ml +++ b/src/X86.ml @@ -403,11 +403,11 @@ let compile cmd env imports code = then [] else [Meta (Printf.sprintf "\t.stabs \"%s:F1\",36,0,0,%s" name f)] @ - (List.mapi (fun i a -> Meta (Printf.sprintf "\t.stabs \"%s:p1\",160,0,0,%d" a ((i*4) + match closure with [] -> 8 | _ -> 12))) args) + (List.mapi (fun i a -> Meta (Printf.sprintf "\t.stabs \"%s:p1\",160,0,0,%d" a ((i*4) + 8))) args) ) @ - [Meta "\t.cfi_startproc"] @ - (if has_closure then [Push edx; Meta "\t.cfi_adjust_cfa_offset\t8"] else []) @ + [Meta "\t.cfi_startproc"; Meta "\t.cfi_adjust_cfa_offset\t4"] @ + (if has_closure then [Push edx; Meta "\t.cfi_adjust_cfa_offset\t4"] else []) @ (if f = cmd#topname then [Mov (M "_init", eax); @@ -420,7 +420,7 @@ let compile cmd env imports code = else [] ) @ [Push ebp; - Meta "\t.cfi_adjust_cfa_offset\t8"; + Meta "\t.cfi_adjust_cfa_offset\t4"; Mov (esp, ebp); Meta "\t.cfi_def_cfa_register\t5"; Binop ("-", M ("$" ^ env#lsize), esp); @@ -801,8 +801,8 @@ let build cmd prog = let objs = find_objects (fst @@ fst prog) cmd#get_include_paths in let buf = Buffer.create 255 in List.iter (fun o -> Buffer.add_string buf o; Buffer.add_string buf " ") objs; - let gcc_cmdline = Printf.sprintf "gcc -m32 %s %s.s %s %s/runtime.a" cmd#get_output_option cmd#basename (Buffer.contents buf) inc in + let gcc_cmdline = Printf.sprintf "gcc %s -m32 %s %s.s %s %s/runtime.a" cmd#get_debug cmd#get_output_option cmd#basename (Buffer.contents buf) inc in Sys.command gcc_cmdline | `Compile -> - Sys.command (Printf.sprintf "gcc -m32 -c %s.s" cmd#basename) + Sys.command (Printf.sprintf "gcc %s -m32 -c %s.s" cmd#get_debug cmd#basename) | _ -> invalid_arg "must not happen" diff --git a/src/version.ml b/src/version.ml index 43dcb82f3..3e305c0e5 100644 --- a/src/version.ml +++ b/src/version.ml @@ -1 +1 @@ -let version = "Version 1.00, 81c060d21, Fri Sep 4 23:45:57 2020 +0300" +let version = "Version 1.00, e2e6d4799, Sun Sep 6 21:39:58 2020 +0300"