Permalink
Browse files

Fix demangle (#672)

* fixed few bugs in bap demangle

* removed a cxxfilt_config.ml

* minor

* fixed bug in cmdline param
  • Loading branch information...
gitoleg authored and ivg committed Jul 5, 2017
1 parent 2592756 commit 5a5a2edf09f07c67a51a039ce822fb279ba3a503
View
@@ -30,6 +30,7 @@ _oasis
/man/bap.1
/lib/bap_config/bap_config.ml
/lib/bap_llvm/bap_llvm_config.ml
/plugins/cxxfilt/cxxfilt_config.ml
/plugins/ida/bap_ida_config.ml
/plugins/objdump/objdump_config.ml
/plugins/api/api_config.ml
@@ -1,5 +1,11 @@
open Core_kernel.Std
let maybe_mangled name =
String.length name > 2 &&
name.[0] = '_' &&
Char.is_uppercase name.[1] &&
Char.is_alpha name.[1]
let demangle_internal str =
let open String in
let open Option.Monad_infix in
@@ -28,6 +34,14 @@ let demangle_internal str =
| "" -> str
| s -> s
let demangle_internal name =
if maybe_mangled name then
Option.try_with (fun () -> demangle_internal name)
else None
let run_internal name =
Option.value_map ~default:name ~f:ident (demangle_internal name)
module Std = struct
type demangler = {
name : string;
@@ -49,7 +63,7 @@ module Std = struct
let internal = {
name = "internal";
run = demangle_internal;
run = run_internal;
}
let () = Demanglers.register internal
@@ -6,5 +6,5 @@ let () =
| Some xs -> xs);
add_variable ~doc:"A path to cxxfilt binary" "cxxfilt_path"
~define:(function
| None -> "cxxfilt"
| None -> "c++filt"
| Some x -> x)

This file was deleted.

Oops, something went wrong.
@@ -12,11 +12,9 @@ let apply demangler proj =
Sub.with_name sub (Demangler.run demangler (Sub.name sub))) |>
Project.with_program proj
let main = function
| None -> ()
| Some demangler ->
Project.register_pass ~autorun:true (apply demangler)
let find_demangler name =
Demanglers.available () |>
List.find ~f:(fun d -> Demangler.name d = name)
let () =
let () = Config.manpage [
@@ -25,12 +23,18 @@ let () =
`S "SEE ALSO";
`P "$(b,bap-plugin-cxxfilt)(1)"
] in
let demangler : demangler option Config.param =
let demanglers =
Demanglers.available () |>
List.map ~f:(fun d -> Demangler.name d, d) in
let doc = sprintf "Demangle all function names using $(docv),
that should be %s" @@ Config.doc_enum demanglers in
Config.(param (some (enum demanglers)) "with" ~docv:"DEMANGLER" ~doc) in
let demangler : string option Config.param =
let doc = sprintf "Demangle all function names using $(docv)" in
Config.(param (some string)) "with" ~docv:"DEMANGLER" ~doc in
Config.when_ready (fun {Config.get=(!)} ->
Future.upon Plugins.loaded (fun () -> main !demangler))
Future.upon Plugins.loaded (fun () ->
Option.iter !demangler (fun demangler ->
match find_demangler demangler with
| Some d -> Project.register_pass ~autorun:true (apply d)
| None ->
let names =
Demanglers.available () |>
List.map ~f:Demangler.name |>
String.concat ~sep:", " in
invalid_argf "Didn't find demangler %s, should be one of: %s\n"
demangler names ())))

0 comments on commit 5a5a2ed

Please sign in to comment.