Skip to content

Commit a053f4c

Browse files
committed
CHB:ARM: show global variables in assembly listing
1 parent 19e1350 commit a053f4c

File tree

1 file changed

+72
-10
lines changed

1 file changed

+72
-10
lines changed

CodeHawk/CHB/bchlibarm32/bCHARMAssemblyInstructions.ml

Lines changed: 72 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
============================================================================= *)
2727

2828
(* chlib *)
29+
open CHNumerical
2930
open CHPretty
3031

3132
(* chutil *)
@@ -34,8 +35,13 @@ open CHPrettyUtil
3435
open CHTraceResult
3536
open CHXmlDocument
3637

38+
(* xprlib *)
39+
open Xprt
40+
open XprTypes
41+
3742
(* bchlib *)
3843
open BCHBasicTypes
44+
open BCHBCTypePretty
3945
open BCHByteUtilities
4046
open BCHDataBlock
4147
open BCHDoubleword
@@ -61,6 +67,9 @@ open BCHDisassembleThumbInstruction
6167
module H = Hashtbl
6268
module TR = CHTraceResult
6369

70+
let x2p = XprToPretty.xpr_formatter#pr_expr
71+
let p2s = CHPrettyUtil.pretty_to_string
72+
let x2s x = p2s (x2p x)
6473

6574
let numArrays = 1000
6675
let arrayLength = 100000
@@ -676,6 +685,67 @@ object (self)
676685
^ " String:<"
677686
^ (fixed_length_string v#to_hex_string 12)
678687
^ "> ... (cont'd)"
688+
689+
else if Option.is_some (memorymap#containing_location a) then
690+
match memorymap#containing_location a with
691+
| None -> ""
692+
| Some gloc ->
693+
let xprv = num_constant_expr a#to_numerical in
694+
let offset_r = gloc#address_offset xprv in
695+
TR.tfold_default
696+
(fun offset ->
697+
match offset with
698+
| XConst (IntConst n) when n#equal numerical_zero ->
699+
" "
700+
^ (fixed_length_string addr 10)
701+
^ " Global variable:<"
702+
^ gloc#name
703+
^ ": "
704+
^ (btype_to_string gloc#btype)
705+
^ ">"
706+
^ "\n "
707+
^ (fixed_length_string addr 10)
708+
^ " GV:<"
709+
^ gloc#name
710+
^ ":0 >: "
711+
^ v#to_hex_string
712+
| XConst (IntConst n) ->
713+
" "
714+
^ (fixed_length_string addr 10)
715+
^ " GV:<"
716+
^ gloc#name
717+
^ ":"
718+
^ (fixed_length_string n#toString 3)
719+
^ ">: "
720+
^ v#to_hex_string
721+
| _ ->
722+
" "
723+
^ (fixed_length_string addr 10)
724+
^ " GV:<"
725+
^ gloc#name
726+
^ ":"
727+
^ (x2s offset)
728+
^ ">: "
729+
^ v#to_hex_string)
730+
(" "
731+
^ (fixed_length_string addr 10)
732+
^ " GV:<"
733+
^ gloc#name
734+
^ ":?>: "
735+
^ v#to_hex_string)
736+
offset_r
737+
738+
else if memorymap#has_elf_symbol v then
739+
let name = memorymap#get_elf_symbol v in
740+
" "
741+
^ (fixed_length_string addr 10)
742+
^ " Sym:<"
743+
^ v#to_hex_string
744+
^ ":"
745+
^ name
746+
^ ">"
747+
^ datarefstr
748+
679749
else if v#equal wordzero then
680750
" "
681751
^ (fixed_length_string addr 10)
@@ -684,6 +754,7 @@ object (self)
684754
" "
685755
^ (fixed_length_string addr 10)
686756
^ " <0xffffffff>"
757+
687758
else if functions_data#is_function_entry_point v then
688759
let name =
689760
if functions_data#has_function_name v then
@@ -698,16 +769,7 @@ object (self)
698769
^ name
699770
^ ">"
700771
^ datarefstr
701-
else if memorymap#has_elf_symbol v then
702-
let name = memorymap#get_elf_symbol v in
703-
" "
704-
^ (fixed_length_string addr 10)
705-
^ " Sym:<"
706-
^ v#to_hex_string
707-
^ ":"
708-
^ name
709-
^ ">"
710-
^ datarefstr
772+
711773
else if elf_header#is_code_address v then
712774
" "
713775
^ (fixed_length_string addr 10)

0 commit comments

Comments
 (0)