Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 20 Apr 2019 10:58:33 +0000 (UTC)
From:      Mark Johnston <markj@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-12@freebsd.org
Subject:   svn commit: r346433 - stable/12/contrib/elftoolchain/libdwarf
Message-ID:  <201904201058.x3KAwXvP085619@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: markj
Date: Sat Apr 20 10:58:33 2019
New Revision: 346433
URL: https://svnweb.freebsd.org/changeset/base/346433

Log:
  MFC r345593:
  Prepend DW_AT_comp_dir to relative line number directory table entries.

Modified:
  stable/12/contrib/elftoolchain/libdwarf/libdwarf_lineno.c
Directory Properties:
  stable/12/   (props changed)

Modified: stable/12/contrib/elftoolchain/libdwarf/libdwarf_lineno.c
==============================================================================
--- stable/12/contrib/elftoolchain/libdwarf/libdwarf_lineno.c	Sat Apr 20 10:56:56 2019	(r346432)
+++ stable/12/contrib/elftoolchain/libdwarf/libdwarf_lineno.c	Sat Apr 20 10:58:33 2019	(r346433)
@@ -33,9 +33,10 @@ _dwarf_lineno_add_file(Dwarf_LineInfo li, uint8_t **p,
     Dwarf_Error *error, Dwarf_Debug dbg)
 {
 	Dwarf_LineFile lf;
-	const char *dirname;
+	FILE *filepath;
+	const char *incdir;
 	uint8_t *src;
-	int slen;
+	size_t slen;
 
 	src = *p;
 
@@ -54,20 +55,33 @@ _dwarf_lineno_add_file(Dwarf_LineInfo li, uint8_t **p,
 		return (DW_DLE_DIR_INDEX_BAD);
 	}
 
-	/* Make full pathname if need. */
+	/* Make a full pathname if needed. */
 	if (*lf->lf_fname != '/') {
-		dirname = compdir;
+		filepath = open_memstream(&lf->lf_fullpath, &slen);
+		if (filepath == NULL) {
+			free(lf);
+			DWARF_SET_ERROR(dbg, error, DW_DLE_MEMORY);
+			return (DW_DLE_MEMORY);
+		}
+
 		if (lf->lf_dirndx > 0)
-			dirname = li->li_incdirs[lf->lf_dirndx - 1];
-		if (dirname != NULL) {
-			slen = strlen(dirname) + strlen(lf->lf_fname) + 2;
-			if ((lf->lf_fullpath = malloc(slen)) == NULL) {
-				free(lf);
-				DWARF_SET_ERROR(dbg, error, DW_DLE_MEMORY);
-				return (DW_DLE_MEMORY);
-			}
-			snprintf(lf->lf_fullpath, slen, "%s/%s", dirname,
-			    lf->lf_fname);
+			incdir = li->li_incdirs[lf->lf_dirndx - 1];
+		else
+			incdir = NULL;
+
+		/*
+		 * Prepend the compilation directory if the directory table
+		 * entry is relative.
+		 */
+		if (incdir == NULL || *incdir != '/')
+			fprintf(filepath, "%s/", compdir);
+		if (incdir != NULL)
+			fprintf(filepath, "%s/", incdir);
+		fprintf(filepath, "%s", lf->lf_fname);
+		if (fclose(filepath) != 0) {
+			free(lf);
+			DWARF_SET_ERROR(dbg, error, DW_DLE_MEMORY);
+			return (DW_DLE_MEMORY);
 		}
 	}
 



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201904201058.x3KAwXvP085619>