Skip to content

Commit cba0a73

Browse files
committed
Add AI generated comments for classes and methods
1 parent 4c829d4 commit cba0a73

17 files changed

+1371
-250
lines changed

elfio/elf_types.hpp

Lines changed: 195 additions & 73 deletions
Large diffs are not rendered by default.

elfio/elfio.hpp

Lines changed: 164 additions & 19 deletions
Large diffs are not rendered by default.

elfio/elfio_array.hpp

Lines changed: 63 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -28,55 +28,86 @@ THE SOFTWARE.
2828
namespace ELFIO {
2929

3030
//------------------------------------------------------------------------------
31+
// Template class for accessing array sections
3132
template <class S, typename T> class array_section_accessor_template
3233
{
3334
public:
3435
//------------------------------------------------------------------------------
36+
// Constructor
3537
explicit array_section_accessor_template( const elfio& elf_file,
36-
S* section )
37-
: elf_file( elf_file ), array_section( section )
38-
{
39-
}
38+
S* section );
4039

4140
//------------------------------------------------------------------------------
42-
Elf_Xword get_entries_num() const
43-
{
44-
Elf_Xword entry_size = sizeof( T );
45-
return array_section->get_size() / entry_size;
46-
}
41+
// Returns the number of entries in the array section
42+
Elf_Xword get_entries_num() const;
4743

4844
//------------------------------------------------------------------------------
49-
bool get_entry( Elf_Xword index, Elf64_Addr& address ) const
50-
{
51-
if ( index >= get_entries_num() ) { // Is index valid
52-
return false;
53-
}
54-
55-
const endianness_convertor& convertor = elf_file.get_convertor();
56-
57-
const T temp = *reinterpret_cast<const T*>( array_section->get_data() +
58-
index * sizeof( T ) );
59-
address = convertor( temp );
60-
61-
return true;
62-
}
45+
// Retrieves an entry from the array section
46+
bool get_entry( Elf_Xword index, Elf64_Addr& address ) const;
6347

6448
//------------------------------------------------------------------------------
65-
void add_entry( Elf64_Addr address )
66-
{
67-
const endianness_convertor& convertor = elf_file.get_convertor();
68-
69-
T temp = convertor( (T)address );
70-
array_section->append_data( reinterpret_cast<char*>( &temp ),
71-
sizeof( temp ) );
72-
}
49+
// Adds an entry to the array section
50+
void add_entry( Elf64_Addr address );
7351

7452
private:
7553
//------------------------------------------------------------------------------
54+
// Reference to the ELF file
7655
const elfio& elf_file;
77-
S* array_section;
56+
//------------------------------------------------------------------------------
57+
// Pointer to the array section
58+
S* array_section;
7859
};
7960

61+
//------------------------------------------------------------------------------
62+
// Constructor
63+
template <class S, typename T>
64+
array_section_accessor_template<S, T>::array_section_accessor_template(
65+
const elfio& elf_file, S* section )
66+
: elf_file( elf_file ), array_section( section )
67+
{
68+
}
69+
70+
//------------------------------------------------------------------------------
71+
// Returns the number of entries in the array section
72+
template <class S, typename T>
73+
Elf_Xword array_section_accessor_template<S, T>::get_entries_num() const
74+
{
75+
Elf_Xword entry_size = sizeof( T );
76+
return array_section->get_size() / entry_size;
77+
}
78+
79+
//------------------------------------------------------------------------------
80+
// Retrieves an entry from the array section
81+
template <class S, typename T>
82+
bool array_section_accessor_template<S, T>::get_entry(
83+
Elf_Xword index, Elf64_Addr& address ) const
84+
{
85+
if ( index >= get_entries_num() ) { // Is index valid
86+
return false;
87+
}
88+
89+
const endianness_convertor& convertor = elf_file.get_convertor();
90+
91+
const T temp = *reinterpret_cast<const T*>( array_section->get_data() +
92+
index * sizeof( T ) );
93+
address = convertor( temp );
94+
95+
return true;
96+
}
97+
98+
//------------------------------------------------------------------------------
99+
// Adds an entry to the array section
100+
template <class S, typename T>
101+
void array_section_accessor_template<S, T>::add_entry( Elf64_Addr address )
102+
{
103+
const endianness_convertor& convertor = elf_file.get_convertor();
104+
105+
T temp = convertor( (T)address );
106+
array_section->append_data( reinterpret_cast<char*>( &temp ),
107+
sizeof( temp ) );
108+
}
109+
110+
// Type aliases for array section accessors
80111
template <typename T = Elf32_Word>
81112
using array_section_accessor = array_section_accessor_template<section, T>;
82113
template <typename T = Elf32_Word>

elfio/elfio_dump.hpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -672,6 +672,7 @@ static const struct note_tag_t
672672
static const ELFIO::Elf_Xword MAX_DATA_ENTRIES = 64;
673673

674674
//------------------------------------------------------------------------------
675+
// Class representing the ELF dump functionality
675676
class dump
676677
{
677678
#define DUMP_DEC_FORMAT( width ) \
@@ -685,6 +686,7 @@ class dump
685686

686687
public:
687688
//------------------------------------------------------------------------------
689+
// Dumps the ELF header information
688690
static void header( std::ostream& out, const elfio& reader )
689691
{
690692
if ( !reader.get_header_size() ) {
@@ -713,6 +715,7 @@ class dump
713715
}
714716

715717
//------------------------------------------------------------------------------
718+
// Dumps the section headers information
716719
static void section_headers( std::ostream& out, const elfio& reader )
717720
{
718721
Elf_Half n = reader.sections.size();
@@ -748,6 +751,7 @@ class dump
748751
}
749752

750753
//------------------------------------------------------------------------------
754+
// Dumps a single section header information
751755
static void section_header( std::ostream& out,
752756
Elf_Half no,
753757
const section* sec,
@@ -792,6 +796,7 @@ class dump
792796
}
793797

794798
//------------------------------------------------------------------------------
799+
// Dumps the segment headers information
795800
static void segment_headers( std::ostream& out, const elfio& reader )
796801
{
797802
Elf_Half n = reader.segments.size();
@@ -836,6 +841,7 @@ class dump
836841
}
837842

838843
//------------------------------------------------------------------------------
844+
// Dumps a single segment header information
839845
static void segment_header( std::ostream& out,
840846
Elf_Half no,
841847
const segment* seg,
@@ -874,6 +880,7 @@ class dump
874880
}
875881

876882
//------------------------------------------------------------------------------
883+
// Dumps the symbol tables information
877884
static void symbol_tables( std::ostream& out, const elfio& reader )
878885
{
879886
for ( const auto& sec : reader.sections ) { // For all sections
@@ -918,6 +925,7 @@ class dump
918925
}
919926

920927
//------------------------------------------------------------------------------
928+
// Dumps a single symbol table entry information
921929
static void symbol_table( std::ostream& out,
922930
Elf_Xword no,
923931
const std::string& name,
@@ -954,6 +962,7 @@ class dump
954962
}
955963

956964
//------------------------------------------------------------------------------
965+
// Dumps the notes information
957966
static void notes( std::ostream& out, const elfio& reader )
958967
{
959968
for ( const auto& sec : reader.sections ) { // For all sections
@@ -1018,6 +1027,7 @@ class dump
10181027
}
10191028

10201029
//------------------------------------------------------------------------------
1030+
// Dumps a single note information
10211031
static void note( std::ostream& out,
10221032
int no,
10231033
Elf_Word type,
@@ -1065,6 +1075,7 @@ class dump
10651075
}
10661076

10671077
//------------------------------------------------------------------------------
1078+
// Dumps the module information
10681079
static void modinfo( std::ostream& out, const elfio& reader )
10691080
{
10701081
for ( const auto& sec : reader.sections ) { // For all sections
@@ -1088,6 +1099,7 @@ class dump
10881099
}
10891100

10901101
//------------------------------------------------------------------------------
1102+
// Dumps the dynamic tags information
10911103
static void dynamic_tags( std::ostream& out, const elfio& reader )
10921104
{
10931105
for ( const auto& sec : reader.sections ) { // For all sections
@@ -1118,6 +1130,7 @@ class dump
11181130
}
11191131

11201132
//------------------------------------------------------------------------------
1133+
// Dumps a single dynamic tag information
11211134
static void dynamic_tag( std::ostream& out,
11221135
Elf_Xword no,
11231136
Elf_Xword tag,
@@ -1137,6 +1150,7 @@ class dump
11371150
}
11381151

11391152
//------------------------------------------------------------------------------
1153+
// Dumps the section data
11401154
static void section_data( std::ostream& out, const section* sec )
11411155
{
11421156
std::ios_base::fmtflags original_flags = out.flags();
@@ -1169,6 +1183,7 @@ class dump
11691183
}
11701184

11711185
//------------------------------------------------------------------------------
1186+
// Dumps all sections data
11721187
static void section_datas( std::ostream& out, const elfio& reader )
11731188
{
11741189
Elf_Half n = reader.sections.size();
@@ -1191,6 +1206,7 @@ class dump
11911206
}
11921207

11931208
//------------------------------------------------------------------------------
1209+
// Dumps the segment data
11941210
static void
11951211
segment_data( std::ostream& out, Elf_Half no, const segment* seg )
11961212
{
@@ -1224,6 +1240,7 @@ class dump
12241240
}
12251241

12261242
//------------------------------------------------------------------------------
1243+
// Dumps all segments data
12271244
static void segment_datas( std::ostream& out, const elfio& reader )
12281245
{
12291246
Elf_Half n = reader.segments.size();

elfio/elfio_dynamic.hpp

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,20 @@ THE SOFTWARE.
2828
namespace ELFIO {
2929

3030
//------------------------------------------------------------------------------
31+
// Template class for accessing dynamic sections
3132
template <class S> class dynamic_section_accessor_template
3233
{
3334
public:
3435
//------------------------------------------------------------------------------
36+
// Constructor
3537
explicit dynamic_section_accessor_template( const elfio& elf_file,
3638
S* section )
3739
: elf_file( elf_file ), dynamic_section( section ), entries_num( 0 )
3840
{
3941
}
4042

4143
//------------------------------------------------------------------------------
44+
// Returns the number of entries in the dynamic section
4245
Elf_Xword get_entries_num() const
4346
{
4447
size_t needed_entry_size = -1;
@@ -70,6 +73,7 @@ template <class S> class dynamic_section_accessor_template
7073
}
7174

7275
//------------------------------------------------------------------------------
76+
// Retrieves an entry from the dynamic section
7377
bool get_entry( Elf_Xword index,
7478
Elf_Xword& tag,
7579
Elf_Xword& value,
@@ -106,6 +110,7 @@ template <class S> class dynamic_section_accessor_template
106110
}
107111

108112
//------------------------------------------------------------------------------
113+
// Adds an entry to the dynamic section
109114
void add_entry( Elf_Xword tag, Elf_Xword value )
110115
{
111116
if ( elf_file.get_class() == ELFCLASS32 ) {
@@ -117,6 +122,7 @@ template <class S> class dynamic_section_accessor_template
117122
}
118123

119124
//------------------------------------------------------------------------------
125+
// Adds an entry with a string value to the dynamic section
120126
void add_entry( Elf_Xword tag, const std::string& str )
121127
{
122128
string_section_accessor strsec(
@@ -125,15 +131,16 @@ template <class S> class dynamic_section_accessor_template
125131
add_entry( tag, value );
126132
}
127133

128-
//------------------------------------------------------------------------------
129134
private:
130135
//------------------------------------------------------------------------------
136+
// Returns the index of the string table
131137
Elf_Half get_string_table_index() const
132138
{
133139
return (Elf_Half)dynamic_section->get_link();
134140
}
135141

136142
//------------------------------------------------------------------------------
143+
// Retrieves a generic entry from the dynamic section
137144
template <class T>
138145
void generic_get_entry_dyn( Elf_Xword index,
139146
Elf_Xword& tag,
@@ -200,6 +207,7 @@ template <class S> class dynamic_section_accessor_template
200207
}
201208

202209
//------------------------------------------------------------------------------
210+
// Adds a generic entry to the dynamic section
203211
template <class T>
204212
void generic_add_entry_dyn( Elf_Xword tag, Elf_Xword value )
205213
{
@@ -258,13 +266,16 @@ template <class S> class dynamic_section_accessor_template
258266
sizeof( entry ) );
259267
}
260268

261-
//------------------------------------------------------------------------------
262269
private:
263-
const elfio& elf_file;
264-
S* dynamic_section;
270+
// Reference to the ELF file
271+
const elfio& elf_file;
272+
// Pointer to the dynamic section
273+
S* dynamic_section;
274+
// Number of entries in the dynamic section
265275
mutable Elf_Xword entries_num;
266276
};
267277

278+
// Type aliases for dynamic section accessors
268279
using dynamic_section_accessor = dynamic_section_accessor_template<section>;
269280
using const_dynamic_section_accessor =
270281
dynamic_section_accessor_template<const section>;

0 commit comments

Comments
 (0)