|
From: <sv...@va...> - 2014-08-22 21:16:11
|
Author: florian
Date: Fri Aug 22 21:16:03 2014
New Revision: 14339
Log:
Change print_file to take a prefix and a file descriptor and remove the
buffer argument. Instead allocate a large enough buffer on the stack.
Also, as print_file was immediately followed by a my_fwrite, move the
my_fwrite call into print_file.
This a sort of a prepatch because we want to use VG_(fdprintf) here
and for that we need to get rid of buffer arithmetic as in
VG_(sprintf)(outbuf + 4, .....)
Modified:
branches/BUF_REMOVAL/callgrind/dump.c
Modified: branches/BUF_REMOVAL/callgrind/dump.c
==============================================================================
--- branches/BUF_REMOVAL/callgrind/dump.c (original)
+++ branches/BUF_REMOVAL/callgrind/dump.c Fri Aug 22 21:16:03 2014
@@ -199,20 +199,25 @@
#endif
}
-static void print_file(HChar* buf, file_node* file)
+static void print_file(Int fd, const char *prefix, file_node* file)
{
+ // 32 for file->number + peripheral characters
+ HChar buf[VG_(strlen)(prefix) + VG_(strlen)(file->name) + 32];
+
if (CLG_(clo).compress_strings) {
CLG_ASSERT(file_dumped != 0);
if (file_dumped[file->number])
- VG_(sprintf)(buf, "(%d)\n", file->number);
+ VG_(sprintf)(buf, "%s(%d)\n", prefix, file->number);
else {
- VG_(sprintf)(buf, "(%d) %s\n",
+ VG_(sprintf)(buf, "%s(%d) %s\n", prefix,
file->number, file->name);
file_dumped[file->number] = True;
}
}
else
- VG_(sprintf)(buf, "%s\n", file->name);
+ VG_(sprintf)(buf, "%s%s\n", prefix, file->name);
+
+ my_fwrite(fd, buf, VG_(strlen)(buf));
}
/*
@@ -369,9 +374,7 @@
}
if (last->file != bbcc->cxt->fn[0]->file) {
- VG_(sprintf)(outbuf, "fl=");
- print_file(outbuf+3, bbcc->cxt->fn[0]->file);
- my_fwrite(fd, outbuf, VG_(strlen)(outbuf));
+ print_file(fd, "fl=", bbcc->cxt->fn[0]->file);
last->file = bbcc->cxt->fn[0]->file;
res = True;
}
@@ -513,11 +516,9 @@
/* if we switch back to orig file, use fe=... */
if (curr->file == func_file)
- VG_(sprintf)(outbuf, "fe=");
+ print_file(fd, "fe=", curr->file);
else
- VG_(sprintf)(outbuf, "fi=");
- print_file(outbuf+3, curr->file);
- my_fwrite(fd, outbuf, VG_(strlen)(outbuf));
+ print_file(fd, "fi=", curr->file);
}
if (CLG_(clo).dump_bbs) {
@@ -673,9 +674,7 @@
* which change the stack, and thus context
*/
if (last->file != target.file) {
- VG_(sprintf)(outbuf, "jfi=");
- print_file(outbuf+4, target.file);
- my_fwrite(fd, outbuf, VG_(strlen)(outbuf));
+ print_file(fd, "jfi=", target.file);
}
if (jcc->from->cxt != jcc->to->cxt) {
@@ -719,9 +718,7 @@
/* file of called position different to current file? */
if (last->file != file) {
- VG_(sprintf)(outbuf, "cfi=");
- print_file(outbuf+4, file);
- my_fwrite(fd, outbuf, VG_(strlen)(outbuf));
+ print_file(fd, "cfi=", file);
}
if (CLG_(clo).mangle_names)
@@ -1511,9 +1508,7 @@
if (ccSum[currSum].p.file != lastFnPos.cxt->fn[0]->file) {
/* switch back to file of function */
- VG_(sprintf)(print_buf, "fe=");
- print_file(print_buf+3, lastFnPos.cxt->fn[0]->file);
- my_fwrite(print_fd, print_buf, VG_(strlen)(print_buf));
+ print_file(print_fd, "fe=", lastFnPos.cxt->fn[0]->file);
}
my_fwrite(print_fd, "\n", 1);
}
|