From 9bf6cbf6dd88777719c5757922aff0190ec46539 Mon Sep 17 00:00:00 2001 From: Joshua Lang Date: Wed, 14 Dec 2016 23:05:00 -0800 Subject: Set CodeView pdb path/name to base name The CodeView pdb path/name field is empty leading windows minidumps to have empty module paths for the binary. This patch sets the path to the base name of the binary. Bug: 33668347 Change-Id: I4138998239b07b54cc36dc2d2e3484c4b63f5435 --- binutils-2.25/bfd/peXXigen.c | 40 +++++++++++++++++++++++++++------------- 1 file changed, 27 insertions(+), 13 deletions(-) (limited to 'binutils-2.25/bfd/peXXigen.c') diff --git a/binutils-2.25/bfd/peXXigen.c b/binutils-2.25/bfd/peXXigen.c index dae32f66..70223404 100644 --- a/binutils-2.25/bfd/peXXigen.c +++ b/binutils-2.25/bfd/peXXigen.c @@ -1138,19 +1138,31 @@ _bfd_XXi_swap_debugdir_out (bfd * abfd, void * inp, void * extp) return sizeof (struct external_IMAGE_DEBUG_DIRECTORY); } +const char * +_bfd_XXi_get_codeview_pdb_name (bfd * abfd) +{ + char * filename_ptr = bfd_get_filename(abfd); + char * last_dir_separator = strrchr(filename_ptr, '/'); + if (last_dir_separator != NULL) { + filename_ptr = last_dir_separator+1; + } + return filename_ptr; +} + static CODEVIEW_INFO * _bfd_XXi_slurp_codeview_record (bfd * abfd, file_ptr where, unsigned long length, CODEVIEW_INFO *cvinfo) { - char buffer[256+1]; - if (bfd_seek (abfd, where, SEEK_SET) != 0) + char buffer [length]; + + if (!cvinfo) return NULL; - if (bfd_bread (buffer, 256, abfd) < 4) + if (bfd_seek (abfd, where, SEEK_SET) != 0) return NULL; - /* Ensure null termination of filename. */ - buffer[256] = '\0'; + if (bfd_bread (buffer, length, abfd) < 4) + return NULL; cvinfo->CVSignature = H_GET_32(abfd, buffer); cvinfo->Age = 0; @@ -1171,7 +1183,7 @@ _bfd_XXi_slurp_codeview_record (bfd * abfd, file_ptr where, unsigned long length memcpy (&(cvinfo->Signature[8]), &(cvinfo70->Signature[8]), 8); cvinfo->SignatureLength = CV_INFO_SIGNATURE_LENGTH; - // cvinfo->PdbFileName = cvinfo70->PdbFileName; + strcpy(cvinfo->PdbFileName, cvinfo70->PdbFileName); return cvinfo; } @@ -1193,7 +1205,9 @@ _bfd_XXi_slurp_codeview_record (bfd * abfd, file_ptr where, unsigned long length unsigned int _bfd_XXi_write_codeview_record (bfd * abfd, file_ptr where, CODEVIEW_INFO *cvinfo) { - unsigned int size = sizeof (CV_INFO_PDB70) + 1; + const char * filename_ptr = _bfd_XXi_get_codeview_pdb_name(abfd); + unsigned int filename_size = strlen(filename_ptr); + unsigned int size = sizeof (CV_INFO_PDB70) + filename_size + 1; CV_INFO_PDB70 *cvinfo70; char buffer[size]; @@ -1211,7 +1225,7 @@ _bfd_XXi_write_codeview_record (bfd * abfd, file_ptr where, CODEVIEW_INFO *cvinf memcpy (&(cvinfo70->Signature[8]), &(cvinfo->Signature[8]), 8); H_PUT_32 (abfd, cvinfo->Age, cvinfo70->Age); - cvinfo70->PdbFileName[0] = '\0'; + strcpy(cvinfo70->PdbFileName, filename_ptr); if (bfd_bwrite (buffer, size, abfd) != size) return 0; @@ -2655,8 +2669,8 @@ pe_print_debugdata (bfd * abfd, void * vfile) if (idd.Type == PE_IMAGE_DEBUG_TYPE_CODEVIEW) { char signature[CV_INFO_SIGNATURE_LENGTH * 2 + 1]; - char buffer[256 + 1]; - CODEVIEW_INFO *cvinfo = (CODEVIEW_INFO *) buffer; + char buffer [idd.SizeOfData]; + CODEVIEW_INFO * cvinfo = (CODEVIEW_INFO *) buffer; /* The debug entry doesn't have to have to be in a section, in which case AddressOfRawData is 0, so always use PointerToRawData. */ @@ -2667,9 +2681,9 @@ pe_print_debugdata (bfd * abfd, void * vfile) for (i = 0; i < cvinfo->SignatureLength; i++) sprintf (&signature[i*2], "%02x", cvinfo->Signature[i] & 0xff); - fprintf (file, "(format %c%c%c%c signature %s age %ld)\n", - buffer[0], buffer[1], buffer[2], buffer[3], - signature, cvinfo->Age); + fprintf (file, "(format %c%c%c%c signature %s age %ld pdb %s)\n", + buffer[0], buffer[1], buffer[2], buffer[3], + signature, cvinfo->Age, cvinfo->PdbFileName); } } -- cgit v1.2.3