27 ROSE_ASSERT(fhdr!=NULL);
30 size_t worst_size = (4+
39 unsigned char *buf =
new unsigned char[worst_size];
43 unsigned char u8_disk;
47 memcpy(buf+at, &u32_disk, 4); at+=4;
51 memcpy(buf+at, &u8_disk, 1); at+=1;
64 if (!astr.empty() && astr[0]==
'z') {
65 for (
size_t i=1; i<astr.size(); i++) {
69 }
else if (
'P'==astr[i]) {
78 memcpy(buf+at, &u32_disk, 4); at+=4;
83 fprintf(stderr,
"%s:%u: warning: unknown PRH encoding (0x%02x)\n",
86 fprintf(stderr,
" (additional frame warnings will be suppressed)\n");
90 }
else if (
'R'==astr[i]) {
93 }
else if (
'S'==astr[i]) {
96 ROSE_ASSERT(!
"invalid .eh_frame augmentation string");
109 std::string retval((
char*)buf, at);
120 sprintf(p,
"%sCIE[%zd].", prefix, idx);
122 sprintf(p,
"%sCIE.", prefix);
126 fprintf(f,
"%s%-*s = %d\n", p, w,
"version",
get_version());
128 fprintf(f,
"%s%-*s = %s\n", p, w,
"sig_frame",
get_sig_frame()?
"yes":
"no");
129 fprintf(f,
"%s%-*s = 0x%08"PRIx64
" (%"PRIu64
")\n", p, w,
"code_align",
131 fprintf(f,
"%s%-*s = 0x%08"PRIx64
" (%"PRId64
")\n", p, w,
"data_align",
133 fprintf(f,
"%s%-*s = 0x%08"PRIx64
" (%"PRIu64
")\n", p, w,
"aug_length",
143 fprintf(f,
"%s%-*s = 0x%08zx (%zu) bytes\n", p, w,
"instructions",
169 ROSE_ASSERT(fhdr!=NULL);
173 unsigned char *buf =
new unsigned char[worst_size];
186 memcpy(buf+at, &u32_disk, 4); at+=4;
188 memcpy(buf+at, &u32_disk, 4); at+=4;
194 fprintf(stderr,
"%s:%u: warning: unknown FDE address encoding (0x%02x)\n",
197 fprintf(stderr,
" (additional frame warnings will be suppressed)\n");
204 if (astr.size()>0 && astr[0]==
'z') {
220 std::string retval((
char*)buf, at);
232 sprintf(p,
"%sFDE[%zd].", prefix, idx);
234 sprintf(p,
"%sFDE.", prefix);
239 fprintf(f,
"%s%-*s = 0x%08"PRIx64
" (%"PRIu64
") bytes\n", p, w,
"size",
get_size(),
get_size());
240 fprintf(f,
"%s%-*s = 0x%08zx (%zu) bytes\n", p, w,
"aug_data",
243 fprintf(f,
"%s%-*s = 0x%08zx (%zu) bytes\n", p, w,
"instructions",
262 ROSE_ASSERT(fhdr!=NULL);
265 std::map<rose_addr_t, SgAsmElfEHFrameEntryCI*> cies;
269 unsigned char u8_disk;
277 if (record_size==0xffffffff) {
280 length_field_size += 8;
288 if (0==cie_back_offset) {
291 cies[record_offset] = cie;
300 at += astr.size() + 1;
313 if (!astr.empty() && astr[0]==
'z') {
314 for (
size_t i=1; i<astr.size(); i++) {
318 }
else if (
'P'==astr[i]) {
338 fprintf(stderr,
"%s:%u: warning: ELF CIE 0x%08"PRIx64
" has unknown PRH encoding 0x%02x\n",
341 fprintf(stderr,
" (additional frame warnings will be suppressed)\n");
346 }
else if (
'R'==astr[i]) {
349 }
else if (
'S'==astr[i]) {
355 fprintf(stderr,
"%s:%u: warning: ELF CIE 0x%08"PRIx64
" has invalid augmentation string \"%s\"\n",
358 fprintf(stderr,
" (additional frame warnings will be suppressed)\n");
366 rose_addr_t init_insn_size = (length_field_size + record_size) - (at - record_offset);
372 rose_addr_t cie_offset = record_offset + length_field_size - cie_back_offset;
373 assert(cies.find(cie_offset)!=cies.end());
378 switch (cie->get_addr_encoding()) {
391 fprintf(stderr,
"%s:%u: ELF CIE 0x%08"PRIx64
", FDE 0x%08"PRIx64
": unknown address encoding: 0x%02x\n",
392 __FILE__, __LINE__,
get_offset()+cie_offset,
get_offset()+record_offset, cie->get_addr_encoding());
397 std::string astring = cie->get_augmentation_string();
398 if (astring.size()>0 && astring[0]==
'z') {
406 rose_addr_t cf_insn_size = (length_field_size + record_size) - (at - record_offset);
411 record_offset += length_field_size + record_size;
447 ROSE_ASSERT(fhdr!=NULL);
456 std::string s = cie->
unparse(
this);
457 if (s.size()<0xffffffff) {
460 write(*fp, at, 4, &u32_disk);
463 u32_disk = 0xffffffff;
465 write(*fp, at, 4, &u32_disk);
469 write(*fp, at, 8, &u64_disk);
478 std::string s = fde->
unparse(
this, cie);
482 if (record_size<0xffffffff) {
485 write(*fp, at, 4, &u32_disk);
488 u32_disk = 0xffffffff;
490 write(*fp, at, 4, &u32_disk);
494 write(*fp, at, 8, &u64_disk);
500 rose_addr_t cie_back_offset = at - last_cie_offset;
503 write(*fp, at, 4, &u32_disk);
516 write(*fp, at, 4, &u32_disk);
528 sprintf(p,
"%sElfEHFrameSection[%zd].", prefix, idx);
530 sprintf(p,
"%sElfEHFrameSection.", prefix);