Better gdb support

This commit is contained in:
Dmitry Boulytchev 2020-09-08 01:50:16 +03:00
parent e2e6d47996
commit 2dbd6808a5
4 changed files with 16 additions and 7 deletions

3
gdb/.gdbinit Normal file
View file

@ -0,0 +1,3 @@
define pp
p (char*) Bstringval ((void*) $arg0)
end

View file

@ -66,6 +66,7 @@ class options args =
val paths = ref [X86.get_std_path ()] val paths = ref [X86.get_std_path ()]
val mode = ref (`Default : [`Default | `Eval | `SM | `Compile ]) val mode = ref (`Default : [`Default | `Eval | `SM | `Compile ])
val curdir = Unix.getcwd () val curdir = Unix.getcwd ()
val debug = ref false
(* Workaround until Ostap starts to memoize properly *) (* Workaround until Ostap starts to memoize properly *)
val const = ref false val const = ref false
(* end of the workaround *) (* end of the workaround *)
@ -87,6 +88,7 @@ class options args =
| "-dp" -> self#set_dump dump_ast | "-dp" -> self#set_dump dump_ast
| "-h" -> self#set_help | "-h" -> self#set_help
| "-v" -> self#set_version | "-v" -> self#set_version
| "-g" -> self#set_debug
| _ -> | _ ->
if opt.[0] = '-' if opt.[0] = '-'
then raise (Commandline_error (Printf.sprintf "Invalid command line specifier ('%s')" opt)) 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 !version then Printf.printf "%s\n" Version.version;
if !help then Printf.printf "%s" help_string if !help then Printf.printf "%s" help_string
method get_debug =
if !debug then "" else "-g"
method set_debug =
debug := true
end end
let main = let main =

View file

@ -403,11 +403,11 @@ let compile cmd env imports code =
then [] then []
else else
[Meta (Printf.sprintf "\t.stabs \"%s:F1\",36,0,0,%s" name f)] @ [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"] @ [Meta "\t.cfi_startproc"; Meta "\t.cfi_adjust_cfa_offset\t4"] @
(if has_closure then [Push edx; Meta "\t.cfi_adjust_cfa_offset\t8"] else []) @ (if has_closure then [Push edx; Meta "\t.cfi_adjust_cfa_offset\t4"] else []) @
(if f = cmd#topname (if f = cmd#topname
then then
[Mov (M "_init", eax); [Mov (M "_init", eax);
@ -420,7 +420,7 @@ let compile cmd env imports code =
else [] else []
) @ ) @
[Push ebp; [Push ebp;
Meta "\t.cfi_adjust_cfa_offset\t8"; Meta "\t.cfi_adjust_cfa_offset\t4";
Mov (esp, ebp); Mov (esp, ebp);
Meta "\t.cfi_def_cfa_register\t5"; Meta "\t.cfi_def_cfa_register\t5";
Binop ("-", M ("$" ^ env#lsize), esp); 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 objs = find_objects (fst @@ fst prog) cmd#get_include_paths in
let buf = Buffer.create 255 in let buf = Buffer.create 255 in
List.iter (fun o -> Buffer.add_string buf o; Buffer.add_string buf " ") objs; 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 Sys.command gcc_cmdline
| `Compile -> | `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" | _ -> invalid_arg "must not happen"

View file

@ -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"