examples/memmap.pl

filter: Statementstmt 100% 19 / 19 Branchbran 100% 2 / 2 Conditioncond 50.0% 1 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 100% 4 / 4 Podpod n/a totaltotal 92.8% 26 / 28 CC 4 SCAR 10.0
CC
4
Cov
96%
memmap
4.0
BEGIN
1.0
BEGIN
1.0
CRAP 2.7
« support/Test/Harness/Point.pm ↑ Summary support/Test/Harness/Iterator.pm »
1 #!/usr/local/bin/perl -w
2 ################################################################################
3 #
4 # Copyright (c) 2002-2020 Marcus Holland-Moritz. All rights reserved.
5 # This program is free software; you can redistribute it and/or modify
6 # it under the same terms as Perl itself.
7 #
8 ################################################################################
9  
10 #===============================================================================
11 #
12 # Print a simple memory map of a structure.
13 #
14 #===============================================================================
15  
16 1 ▶use Convert::Binary::C;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 1 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20 #-----------------------------------------------------
21 # Create an object, configure it, and parse some code.
22 #-----------------------------------------------------
23  
24 1 my $c = Convert::Binary::C->new( PointerSize => 4,
25 LongSize => 4,
26 ShortSize => 2,
27 Alignment => 4 )
28 ->parse( <<'ENDC' );
29  
30 typedef unsigned long u_32;
31  
32 typedef struct _LinkedList * LinkedList;
33 typedef struct _HashTable * HashTable;
34  
35 typedef struct {
36 enum {
37 BO_BIG_ENDIAN,
38 BO_LITTLE_ENDIAN
39 } bo;
40 } ArchSpecs;
41  
42 typedef struct {
43 char *buffer;
44 long pos, length;
45 } Buffer;
46  
47 typedef struct {
48 unsigned alignment;
49 unsigned int_size;
50 unsigned short_size;
51 unsigned long_size;
52 unsigned long_long_size;
53 int enum_size;
54 unsigned ptr_size;
55 unsigned float_size;
56 unsigned double_size;
57 unsigned long_double_size;
58 u_32 flags;
59 u_32 keywords;
60 LinkedList disabled_keywords;
61 LinkedList includes;
62 LinkedList defines;
63 LinkedList assertions;
64 HashTable keyword_map;
65 } CParseConfig;
66  
67 typedef struct {
68 LinkedList enums;
69 LinkedList structs;
70 LinkedList typedef_lists;
71 HashTable htEnumerators;
72 HashTable htEnums;
73 HashTable htStructs;
74 HashTable htTypedefs;
75 HashTable htFiles;
76 char *errstr;
77 } CParseInfo;
78  
79 typedef struct {
80 char *bufptr;
81 unsigned alignment;
82 unsigned align_base;
83 int dataTooShortFlag;
84 Buffer buf;
85 CParseConfig cfg;
86 CParseInfo cpi;
87 ArchSpecs as;
88 enum {
89 ET_INTEGER, ET_STRING, ET_BOTH
90 } enumType;
91 } CBC;
92  
93 ENDC
94  
95 #-------------------------------------------------
96 # Print the memory map for type 'CBC' with a base
97 # address of 0x01500000.
98 #-------------------------------------------------
99  
100 1 memmap( $c, 'CBC', 0x01500000 );
101  
102 #==========================================================
103 # SUBROUTINES
104 #==========================================================
105  
106 sub memmap
107 {
108 1 ▶ my($c, $type, $start) = @_;
Subroutine memmap: called CC=4 SCAR=13.9
109 1 ▶ $start ||= 0;
Condition50%1/2
$start ||= 0
l!l
10
MC/DC0%0/1
$start ||= 0
$start
Truth table50%1/2
A
A= $start
Aresult
11
00
110  
111 1 my $afmt = '%0' . 2*$c->PointerSize . 'X';
112  
113 1 for my $offset ( 0 .. $c->sizeof( $type ) - 1 ) {
114 140 my $m = $c->member( $type, $offset );
115 140 ▶ rindex( $m, '+' ) < 0 or next;
Branch: 1 branch
BranchTrueFalseTotal
rindex($m, "+") == -1 or next 105 35 140
116 35 my $t = $c->typeof( $type.$m );
117 35 printf "$afmt %-16s %s\n", $start+$offset, $t, $m;
118 }
119 }
« support/Test/Harness/Point.pm ↑ Summary support/Test/Harness/Iterator.pm »