EventMapping* CLG_(dumpmap) = 0;
-/* Temporary output buffer for
- * print_fn_pos, fprint_apos, fprint_fcost, fprint_jcc,
- * fprint_fcc_ln, dump_run_info, dump_state_info
- */
-static HChar outbuf[FILENAME_LEN + FN_NAME_LEN + OBJ_NAME_LEN + COSTS_LEN];
-
Int CLG_(get_dump_counter)(void)
{
return out_counter;
}
-#if 0
-static __inline__
-static void my_fwrite(Int fd, const HChar* buf, Int len)
+static void print_obj(VgFile *fp, const HChar* prefix, obj_node* obj)
{
- VG_(write)(fd, buf, len);
-}
-#else
-
-#define FWRITE_BUFSIZE 32000
-#define FWRITE_THROUGH 10000
-static HChar fwrite_buf[FWRITE_BUFSIZE];
-static Int fwrite_pos;
-static Int fwrite_fd = -1;
-
-static __inline__
-void fwrite_flush(void)
-{
- if ((fwrite_fd>=0) && (fwrite_pos>0))
- VG_(write)(fwrite_fd, fwrite_buf, fwrite_pos);
- fwrite_pos = 0;
-}
-
-static void my_fwrite(Int fd, const HChar* buf, Int len)
-{
- if (fwrite_fd != fd) {
- fwrite_flush();
- fwrite_fd = fd;
- }
- if (len > FWRITE_THROUGH) {
- fwrite_flush();
- VG_(write)(fd, buf, len);
- return;
- }
- if (FWRITE_BUFSIZE - fwrite_pos <= len) fwrite_flush();
- VG_(strncpy)(fwrite_buf + fwrite_pos, buf, len);
- fwrite_pos += len;
-}
-#endif
-
-
-static void print_obj(HChar* buf, obj_node* obj)
-{
- //int n;
-
if (CLG_(clo).compress_strings) {
CLG_ASSERT(obj_dumped != 0);
if (obj_dumped[obj->number])
- /*n =*/ VG_(sprintf)(buf, "(%d)\n", obj->number);
+ VG_(fprintf)(fp, "%s(%d)\n", prefix, obj->number);
else {
- /*n =*/ VG_(sprintf)(buf, "(%d) %s\n",
- obj->number, obj->name);
+ VG_(fprintf)(fp, "%s(%d) %s\n", prefix, obj->number, obj->name);
}
}
else
- /*n =*/ VG_(sprintf)(buf, "%s\n", obj->name);
+ VG_(fprintf)(fp, "%s%s\n", prefix, obj->name);
#if 0
/* add mapping parameters the first time a object is dumped
* format: mp=0xSTART SIZE 0xOFFSET */
if (!obj_dumped[obj->number]) {
obj_dumped[obj->number];
- VG_(sprintf)(buf+n, "mp=%p %p %p\n",
+ VG_(fprintf)(fp, "mp=%p %p %p\n",
pos->obj->start, pos->obj->size, pos->obj->offset);
}
#else
#endif
}
-static void print_file(Int fd, const char *prefix, file_node* file)
+static void print_file(VgFile *fp, const char *prefix, const 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, "%s(%d)\n", prefix, file->number);
+ VG_(fprintf)(fp, "%s(%d)\n", prefix, file->number);
else {
- VG_(sprintf)(buf, "%s(%d) %s\n", prefix,
- file->number, file->name);
+ VG_(fprintf)(fp, "%s(%d) %s\n", prefix, file->number, file->name);
file_dumped[file->number] = True;
}
}
else
- VG_(sprintf)(buf, "%s%s\n", prefix, file->name);
-
- my_fwrite(fd, buf, VG_(strlen)(buf));
+ VG_(fprintf)(fp, "%s%s\n", prefix, file->name);
}
/*
* tag can be "fn", "cfn", "jfn"
*/
-static void print_fn(Int fd, HChar* buf, const HChar* tag, fn_node* fn)
+static void print_fn(VgFile *fp, const HChar* tag, const fn_node* fn)
{
- int p;
- p = VG_(sprintf)(buf, "%s=",tag);
+ VG_(fprintf)(fp, "%s=",tag);
if (CLG_(clo).compress_strings) {
CLG_ASSERT(fn_dumped != 0);
if (fn_dumped[fn->number])
- p += VG_(sprintf)(buf+p, "(%d)\n", fn->number);
+ VG_(fprintf)(fp, "(%d)\n", fn->number);
else {
- p += VG_(sprintf)(buf+p, "(%d) %s\n",
- fn->number, fn->name);
+ VG_(fprintf)(fp, "(%d) %s\n", fn->number, fn->name);
fn_dumped[fn->number] = True;
}
}
else
- p += VG_(sprintf)(buf+p, "%s\n", fn->name);
-
- my_fwrite(fd, buf, p);
+ VG_(fprintf)(fp, "%s\n", fn->name);
}
-static void print_mangled_fn(Int fd, HChar* buf, const HChar* tag,
+static void print_mangled_fn(VgFile *fp, const HChar* tag,
Context* cxt, int rec_index)
{
- int p, i;
+ int i;
if (CLG_(clo).compress_strings && CLG_(clo).compress_mangled) {
CLG_ASSERT(cxt_dumped != 0);
if (cxt_dumped[cxt->base_number+rec_index]) {
- p = VG_(sprintf)(buf, "%s=(%d)\n",
+ VG_(fprintf)(fp, "%s=(%d)\n",
tag, cxt->base_number + rec_index);
- my_fwrite(fd, buf, p);
return;
}
CLG_ASSERT(cxt->fn[i-1]->pure_cxt != 0);
n = cxt->fn[i-1]->pure_cxt->base_number;
if (cxt_dumped[n]) continue;
- p = VG_(sprintf)(buf, "%s=(%d) %s\n",
+ VG_(fprintf)(fp, "%s=(%d) %s\n",
tag, n, cxt->fn[i-1]->name);
- my_fwrite(fd, buf, p);
cxt_dumped[n] = True;
last = cxt->fn[i-1]->pure_cxt;
/* If the last context was the context to print, we are finished */
if ((last == cxt) && (rec_index == 0)) return;
- p = VG_(sprintf)(buf, "%s=(%d) (%d)", tag,
+ VG_(fprintf)(fp, "%s=(%d) (%d)", tag,
cxt->base_number + rec_index,
cxt->fn[0]->pure_cxt->base_number);
if (rec_index >0)
- p += VG_(sprintf)(buf+p, "'%d", rec_index +1);
+ VG_(fprintf)(fp, "'%d", rec_index +1);
for(i=1;i<cxt->size;i++)
- p += VG_(sprintf)(buf+p, "'(%d)",
+ VG_(fprintf)(fp, "'(%d)",
cxt->fn[i]->pure_cxt->base_number);
- p += VG_(sprintf)(buf+p, "\n");
- my_fwrite(fd, buf, p);
+ VG_(fprintf)(fp, "\n");
cxt_dumped[cxt->base_number+rec_index] = True;
return;
}
- p = VG_(sprintf)(buf, "%s=", tag);
+ VG_(fprintf)(fp, "%s=", tag);
if (CLG_(clo).compress_strings) {
CLG_ASSERT(cxt_dumped != 0);
if (cxt_dumped[cxt->base_number+rec_index]) {
- p += VG_(sprintf)(buf+p, "(%d)\n", cxt->base_number + rec_index);
- my_fwrite(fd, buf, p);
+ VG_(fprintf)(fp, "(%d)\n", cxt->base_number + rec_index);
return;
}
else {
- p += VG_(sprintf)(buf+p, "(%d) ", cxt->base_number + rec_index);
+ VG_(fprintf)(fp, "(%d) ", cxt->base_number + rec_index);
cxt_dumped[cxt->base_number+rec_index] = True;
}
}
- p += VG_(sprintf)(buf+p, "%s", cxt->fn[0]->name);
+ VG_(fprintf)(fp, "%s", cxt->fn[0]->name);
if (rec_index >0)
- p += VG_(sprintf)(buf+p, "'%d", rec_index +1);
+ VG_(fprintf)(fp, "'%d", rec_index +1);
for(i=1;i<cxt->size;i++)
- p += VG_(sprintf)(buf+p, "'%s", cxt->fn[i]->name);
+ VG_(fprintf)(fp, "'%s", cxt->fn[i]->name);
- p += VG_(sprintf)(buf+p, "\n");
- my_fwrite(fd, buf, p);
+ VG_(fprintf)(fp, "\n");
}
* the <last> position, update <last>
* Return True if something changes.
*/
-static Bool print_fn_pos(int fd, FnPos* last, BBCC* bbcc)
+static Bool print_fn_pos(VgFile *fp, FnPos* last, BBCC* bbcc)
{
Bool res = False;
if (!CLG_(clo).mangle_names) {
if (last->rec_index != bbcc->rec_index) {
- VG_(sprintf)(outbuf, "rec=%d\n\n", bbcc->rec_index);
- my_fwrite(fd, outbuf, VG_(strlen)(outbuf));
+ VG_(fprintf)(fp, "rec=%d\n\n", bbcc->rec_index);
last->rec_index = bbcc->rec_index;
last->cxt = 0; /* reprint context */
res = True;
if (curr_from == 0) {
if (last_from != 0) {
/* switch back to no context */
- VG_(sprintf)(outbuf, "frfn=(spontaneous)\n");
- my_fwrite(fd, outbuf, VG_(strlen)(outbuf));
+ VG_(fprintf)(fp, "frfn=(spontaneous)\n");
res = True;
}
}
else if (last_from != curr_from) {
- print_fn(fd,outbuf,"frfn", curr_from);
+ print_fn(fp, "frfn", curr_from);
res = True;
}
last->cxt = bbcc->cxt;
}
if (last->obj != bbcc->cxt->fn[0]->file->obj) {
- VG_(sprintf)(outbuf, "ob=");
- print_obj(outbuf+3, bbcc->cxt->fn[0]->file->obj);
- my_fwrite(fd, outbuf, VG_(strlen)(outbuf));
+ print_obj(fp, "ob=", bbcc->cxt->fn[0]->file->obj);
last->obj = bbcc->cxt->fn[0]->file->obj;
res = True;
}
if (last->file != bbcc->cxt->fn[0]->file) {
- print_file(fd, "fl=", bbcc->cxt->fn[0]->file);
+ print_file(fp, "fl=", bbcc->cxt->fn[0]->file);
last->file = bbcc->cxt->fn[0]->file;
res = True;
}
if (!CLG_(clo).mangle_names) {
if (last->fn != bbcc->cxt->fn[0]) {
- print_fn(fd,outbuf, "fn", bbcc->cxt->fn[0]);
+ print_fn(fp, "fn", bbcc->cxt->fn[0]);
last->fn = bbcc->cxt->fn[0];
res = True;
}
if ((last->rec_index != bbcc->rec_index) ||
(last->cxt != bbcc->cxt)) {
- print_mangled_fn(fd, outbuf, "fn", bbcc->cxt, bbcc->rec_index);
+ print_mangled_fn(fp, "fn", bbcc->cxt, bbcc->rec_index);
last->fn = bbcc->cxt->fn[0];
last->rec_index = bbcc->rec_index;
res = True;
* print position change inside of a BB (last -> curr)
* this doesn't update last to curr!
*/
-static void fprint_apos(Int fd, AddrPos* curr, AddrPos* last, file_node* func_file)
+static void fprint_apos(VgFile *fp, AddrPos* curr, AddrPos* last,
+ file_node* func_file)
{
CLG_ASSERT(curr->file != 0);
CLG_DEBUG(2, " print_apos(file '%s', line %d, bb %#lx, addr %#lx) fnFile '%s'\n",
/* if we switch back to orig file, use fe=... */
if (curr->file == func_file)
- print_file(fd, "fe=", curr->file);
+ print_file(fp, "fe=", curr->file);
else
- print_file(fd, "fi=", curr->file);
+ print_file(fp, "fi=", curr->file);
}
if (CLG_(clo).dump_bbs) {
if (curr->line != last->line) {
- VG_(sprintf)(outbuf, "ln=%d\n", curr->line);
- my_fwrite(fd, outbuf, VG_(strlen)(outbuf));
+ VG_(fprintf)(fp, "ln=%d\n", curr->line);
}
}
}
* This doesn't set last to curr afterwards!
*/
static
-void fprint_pos(Int fd, AddrPos* curr, AddrPos* last)
+void fprint_pos(VgFile *fp, const AddrPos* curr, const AddrPos* last)
{
if (0) //CLG_(clo).dump_bbs)
- VG_(sprintf)(outbuf, "%lu ", curr->addr - curr->bb_addr);
+ VG_(fprintf)(fp, "%lu ", curr->addr - curr->bb_addr);
else {
- int p = 0;
if (CLG_(clo).dump_instr) {
int diff = curr->addr - last->addr;
if ( CLG_(clo).compress_pos && (last->addr >0) &&
(diff > -100) && (diff < 100)) {
if (diff >0)
- p = VG_(sprintf)(outbuf, "+%d ", diff);
+ VG_(fprintf)(fp, "+%d ", diff);
else if (diff==0)
- p = VG_(sprintf)(outbuf, "* ");
+ VG_(fprintf)(fp, "* ");
else
- p = VG_(sprintf)(outbuf, "%d ", diff);
+ VG_(fprintf)(fp, "%d ", diff);
}
else
- p = VG_(sprintf)(outbuf, "%#lx ", curr->addr);
+ VG_(fprintf)(fp, "%#lx ", curr->addr);
}
if (CLG_(clo).dump_bb) {
if ( CLG_(clo).compress_pos && (last->bb_addr >0) &&
(diff > -100) && (diff < 100)) {
if (diff >0)
- p += VG_(sprintf)(outbuf+p, "+%d ", diff);
+ VG_(fprintf)(fp, "+%d ", diff);
else if (diff==0)
- p += VG_(sprintf)(outbuf+p, "* ");
+ VG_(fprintf)(fp, "* ");
else
- p += VG_(sprintf)(outbuf+p, "%d ", diff);
+ VG_(fprintf)(fp, "%d ", diff);
}
else
- p += VG_(sprintf)(outbuf+p, "%#lx ", curr->bb_addr);
+ VG_(fprintf)(fp, "%#lx ", curr->bb_addr);
}
if (CLG_(clo).dump_line) {
(diff > -100) && (diff < 100)) {
if (diff >0)
- VG_(sprintf)(outbuf+p, "+%d ", diff);
+ VG_(fprintf)(fp, "+%d ", diff);
else if (diff==0)
- VG_(sprintf)(outbuf+p, "* ");
+ VG_(fprintf)(fp, "* ");
else
- VG_(sprintf)(outbuf+p, "%d ", diff);
+ VG_(fprintf)(fp, "%d ", diff);
}
else
- VG_(sprintf)(outbuf+p, "%u ", curr->line);
+ VG_(fprintf)(fp, "%u ", curr->line);
}
}
- my_fwrite(fd, outbuf, VG_(strlen)(outbuf));
}
*/
static
-void fprint_cost(int fd, EventMapping* es, ULong* cost)
+void fprint_cost(VgFile *fp, const EventMapping* es, const ULong* cost)
{
HChar *mcost = CLG_(mappingcost_as_string)(es, cost);
- VG_(sprintf)(outbuf, "%s\n", mcost);
- my_fwrite(fd, outbuf, VG_(strlen)(outbuf));
+ VG_(fprintf)(fp, "%s\n", mcost);
CLG_FREE(mcost);
- return;
}
* funcPos is the source position of the first line of actual function.
* Something is written only if cost != 0; returns True in this case.
*/
-static void fprint_fcost(Int fd, AddrCost* c, AddrPos* last)
+static void fprint_fcost(VgFile *fp, AddrCost* c, AddrPos* last)
{
CLG_DEBUGIF(3) {
CLG_DEBUG(2, " print_fcost(file '%s', line %d, bb %#lx, addr %#lx):\n",
CLG_(print_cost)(-5, CLG_(sets).full, c->cost);
}
- fprint_pos(fd, &(c->p), last);
+ fprint_pos(fp, &(c->p), last);
copy_apos( last, &(c->p) ); /* update last to current position */
- fprint_cost(fd, CLG_(dumpmap), c->cost);
+ fprint_cost(fp, CLG_(dumpmap), c->cost);
/* add cost to total */
CLG_(add_and_zero_cost)( CLG_(sets).full, dump_total_cost, c->cost );
/* Write out the calls from jcc (at pos)
*/
-static void fprint_jcc(Int fd, jCC* jcc, AddrPos* curr, AddrPos* last, ULong ecounter)
+static void fprint_jcc(VgFile *fp, jCC* jcc, AddrPos* curr, AddrPos* last,
+ ULong ecounter)
{
static AddrPos target;
file_node* file;
* which change the stack, and thus context
*/
if (last->file != target.file) {
- print_file(fd, "jfi=", target.file);
+ print_file(fp, "jfi=", target.file);
}
if (jcc->from->cxt != jcc->to->cxt) {
if (CLG_(clo).mangle_names)
- print_mangled_fn(fd, outbuf, "jfn",
+ print_mangled_fn(fp, "jfn",
jcc->to->cxt, jcc->to->rec_index);
else
- print_fn(fd, outbuf, "jfn", jcc->to->cxt->fn[0]);
+ print_fn(fp, "jfn", jcc->to->cxt->fn[0]);
}
if (jcc->jmpkind == jk_CondJump) {
/* format: jcnd=<followed>/<executions> <target> */
- VG_(sprintf)(outbuf, "jcnd=%llu/%llu ",
+ VG_(fprintf)(fp, "jcnd=%llu/%llu ",
jcc->call_counter, ecounter);
}
else {
/* format: jump=<jump count> <target> */
- VG_(sprintf)(outbuf, "jump=%llu ",
+ VG_(fprintf)(fp, "jump=%llu ",
jcc->call_counter);
}
- my_fwrite(fd, outbuf, VG_(strlen)(outbuf));
- fprint_pos(fd, &target, last);
- my_fwrite(fd, "\n", 1);
- fprint_pos(fd, curr, last);
- my_fwrite(fd, "\n", 1);
+ fprint_pos(fp, &target, last);
+ VG_(fprintf)(fp, "\n");
+ fprint_pos(fp, curr, last);
+ VG_(fprintf)(fp, "\n");
jcc->call_counter = 0;
return;
/* object of called position different to object of this function?*/
if (jcc->from->cxt->fn[0]->file->obj != obj) {
- VG_(sprintf)(outbuf, "cob=");
- print_obj(outbuf+4, obj);
- my_fwrite(fd, outbuf, VG_(strlen)(outbuf));
+ print_obj(fp, "cob=", obj);
}
/* file of called position different to current file? */
if (last->file != file) {
- print_file(fd, "cfi=", file);
+ print_file(fp, "cfi=", file);
}
if (CLG_(clo).mangle_names)
- print_mangled_fn(fd, outbuf, "cfn", jcc->to->cxt, jcc->to->rec_index);
+ print_mangled_fn(fp, "cfn", jcc->to->cxt, jcc->to->rec_index);
else
- print_fn(fd, outbuf, "cfn", jcc->to->cxt->fn[0]);
+ print_fn(fp, "cfn", jcc->to->cxt->fn[0]);
if (!CLG_(is_zero_cost)( CLG_(sets).full, jcc->cost)) {
- VG_(sprintf)(outbuf, "calls=%llu ",
+ VG_(fprintf)(fp, "calls=%llu ",
jcc->call_counter);
- my_fwrite(fd, outbuf, VG_(strlen)(outbuf));
- fprint_pos(fd, &target, last);
- my_fwrite(fd, "\n", 1);
- fprint_pos(fd, curr, last);
- fprint_cost(fd, CLG_(dumpmap), jcc->cost);
+ fprint_pos(fp, &target, last);
+ VG_(fprintf)(fp, "\n");
+ fprint_pos(fp, curr, last);
+ fprint_cost(fp, CLG_(dumpmap), jcc->cost);
CLG_(init_cost)( CLG_(sets).full, jcc->cost );
* - JCCs of the unique jump of this BB
* returns True if something was written
*/
-static Bool fprint_bbcc(Int fd, BBCC* bbcc, AddrPos* last)
+static Bool fprint_bbcc(VgFile *fp, BBCC* bbcc, AddrPos* last)
{
InstrInfo* instr_info;
ULong ecounter;
if (!CLG_(is_zero_cost)( CLG_(sets).full, currCost->cost )) {
something_written = True;
- fprint_apos(fd, &(currCost->p), last, bbcc->cxt->fn[0]->file);
- fprint_fcost(fd, currCost, last);
+ fprint_apos(fp, &(currCost->p), last, bbcc->cxt->fn[0]->file);
+ fprint_fcost(fp, currCost, last);
}
/* switch buffers */
if (jcc_count>0) {
if (!CLG_(is_zero_cost)( CLG_(sets).full, currCost->cost )) {
/* no need to switch buffers, as position is the same */
- fprint_apos(fd, &(currCost->p), last, bbcc->cxt->fn[0]->file);
- fprint_fcost(fd, currCost, last);
+ fprint_apos(fp, &(currCost->p), last, bbcc->cxt->fn[0]->file);
+ fprint_fcost(fp, currCost, last);
}
get_debug_pos(bbcc, bb_addr(bb)+instr_info->instr_offset, &(currCost->p));
- fprint_apos(fd, &(currCost->p), last, bbcc->cxt->fn[0]->file);
+ fprint_apos(fp, &(currCost->p), last, bbcc->cxt->fn[0]->file);
something_written = True;
for(jcc=bbcc->jmp[jmp].jcc_list; jcc; jcc=jcc->next_from) {
if (((jcc->jmpkind != jk_Call) && (jcc->call_counter >0)) ||
(!CLG_(is_zero_cost)( CLG_(sets).full, jcc->cost )))
- fprint_jcc(fd, jcc, &(currCost->p), last, ecounter);
+ fprint_jcc(fp, jcc, &(currCost->p), last, ecounter);
}
}
}
if (!CLG_(is_zero_cost)( CLG_(sets).full, currCost->cost )) {
/* no need to switch buffers, as position is the same */
- fprint_apos(fd, &(currCost->p), last, bbcc->cxt->fn[0]->file);
- fprint_fcost(fd, currCost, last);
+ fprint_apos(fp, &(currCost->p), last, bbcc->cxt->fn[0]->file);
+ fprint_fcost(fp, currCost, last);
}
get_debug_pos(bbcc, bb_jmpaddr(bb), &(currCost->p));
- fprint_apos(fd, &(currCost->p), last, bbcc->cxt->fn[0]->file);
+ fprint_apos(fp, &(currCost->p), last, bbcc->cxt->fn[0]->file);
something_written = True;
/* first, print skipped costs for calls */
CLG_(add_and_zero_cost)( CLG_(sets).full,
currCost->cost, bbcc->skipped );
#if 0
- VG_(sprintf)(outbuf, "# Skipped\n");
- my_fwrite(fd, outbuf, VG_(strlen)(outbuf));
+ VG_(fprintf)(fp, "# Skipped\n");
#endif
- fprint_fcost(fd, currCost, last);
+ fprint_fcost(fp, currCost, last);
}
if (jcc_count > 0)
if ( ((jcc->jmpkind != jk_Call) && (jcc->call_counter >0)) ||
(!CLG_(is_zero_cost)( CLG_(sets).full, jcc->cost )))
- fprint_jcc(fd, jcc, &(currCost->p), last, ecounter);
+ fprint_jcc(fp, jcc, &(currCost->p), last, ecounter);
}
}
if (!CLG_(is_zero_cost)( CLG_(sets).full, currCost->cost )) {
something_written = True;
- fprint_apos(fd, &(currCost->p), last, bbcc->cxt->fn[0]->file);
- fprint_fcost(fd, currCost, last);
+ fprint_apos(fp, &(currCost->p), last, bbcc->cxt->fn[0]->file);
+ fprint_fcost(fp, currCost, last);
}
- if (CLG_(clo).dump_bbs) my_fwrite(fd, "\n", 1);
+ if (CLG_(clo).dump_bbs) VG_(fprintf)(fp, "\n");
/* when every cost was immediatly written, we must have done so,
* as this function is only called when there's cost in a BBCC
-static void fprint_cost_ln(int fd, const HChar* prefix,
- EventMapping* em, ULong* cost)
+static void fprint_cost_ln(VgFile *fp, const HChar* prefix,
+ const EventMapping* em, const ULong* cost)
{
HChar *mcost = CLG_(mappingcost_as_string)(em, cost);
- VG_(sprintf)(outbuf, "%s%s\n", prefix, mcost);
- my_fwrite(fd, outbuf, VG_(strlen)(outbuf));
+ VG_(fprintf)(fp, "%s%s\n", prefix, mcost);
CLG_FREE(mcost);
}
*
* Returns the file descriptor, and -1 on error (no write permission)
*/
-static int new_dumpfile(HChar buf[BUF_LEN], int tid, const HChar* trigger)
+static VgFile *new_dumpfile(int tid, const HChar* trigger)
{
Bool appending = False;
- int i, fd;
+ int i;
FullCost sum = 0;
- SysRes res;
+ VgFile *fp;
CLG_ASSERT(dumps_initialized);
CLG_ASSERT(filename != 0);
if (CLG_(clo).separate_threads)
VG_(sprintf)(filename+i, "-%02d", tid);
- res = VG_(open)(filename, VKI_O_WRONLY|VKI_O_TRUNC, 0);
+ fp = VG_(fopen)(filename, VKI_O_WRONLY|VKI_O_TRUNC, 0);
}
else {
VG_(sprintf)(filename, "%s", out_file);
- res = VG_(open)(filename, VKI_O_WRONLY|VKI_O_APPEND, 0);
- if (!sr_isError(res) && out_counter>1)
+ fp = VG_(fopen)(filename, VKI_O_WRONLY|VKI_O_APPEND, 0);
+ if (fp && out_counter>1)
appending = True;
}
- if (sr_isError(res)) {
- res = VG_(open)(filename, VKI_O_CREAT|VKI_O_WRONLY,
- VKI_S_IRUSR|VKI_S_IWUSR);
- if (sr_isError(res)) {
+ if (fp == NULL) {
+ fp = VG_(fopen)(filename, VKI_O_CREAT|VKI_O_WRONLY,
+ VKI_S_IRUSR|VKI_S_IWUSR);
+ if (fp == NULL) {
/* If the file can not be opened for whatever reason (conflict
between multiple supervised processes?), give up now. */
file_err();
}
}
- fd = (Int) sr_Res(res);
CLG_DEBUG(2, " new_dumpfile '%s'\n", filename);
if (!appending) {
/* version */
- VG_(sprintf)(buf, "version: 1\n");
- my_fwrite(fd, buf, VG_(strlen)(buf));
+ VG_(fprintf)(fp, "version: 1\n");
/* creator */
- VG_(sprintf)(buf, "creator: callgrind-" VERSION "\n");
- my_fwrite(fd, buf, VG_(strlen)(buf));
+ VG_(fprintf)(fp, "creator: callgrind-" VERSION "\n");
/* "pid:" line */
- VG_(sprintf)(buf, "pid: %d\n", VG_(getpid)());
- my_fwrite(fd, buf, VG_(strlen)(buf));
+ VG_(fprintf)(fp, "pid: %d\n", VG_(getpid)());
/* "cmd:" line */
- VG_(strcpy)(buf, "cmd: ");
- my_fwrite(fd, buf, VG_(strlen)(buf));
- my_fwrite(fd, cmdbuf, VG_(strlen)(cmdbuf));
+ VG_(fprintf)(fp, "cmd: %s", cmdbuf);
}
- VG_(sprintf)(buf, "\npart: %d\n", out_counter);
- my_fwrite(fd, buf, VG_(strlen)(buf));
+ VG_(fprintf)(fp, "\npart: %d\n", out_counter);
if (CLG_(clo).separate_threads) {
- VG_(sprintf)(buf, "thread: %d\n", tid);
- my_fwrite(fd, buf, VG_(strlen)(buf));
+ VG_(fprintf)(fp, "thread: %d\n", tid);
}
/* "desc:" lines */
if (!appending) {
- my_fwrite(fd, "\n", 1);
+ VG_(fprintf)(fp, "\n");
#if 0
/* Global options changing the tracing behaviour */
- VG_(sprintf)(buf, "\ndesc: Option: --skip-plt=%s\n",
+ VG_(fprintf)(fp, "\ndesc: Option: --skip-plt=%s\n",
CLG_(clo).skip_plt ? "yes" : "no");
- my_fwrite(fd, buf, VG_(strlen)(buf));
- VG_(sprintf)(buf, "desc: Option: --collect-jumps=%s\n",
+ VG_(fprintf)(fp, "desc: Option: --collect-jumps=%s\n",
CLG_(clo).collect_jumps ? "yes" : "no");
- my_fwrite(fd, buf, VG_(strlen)(buf));
- VG_(sprintf)(buf, "desc: Option: --separate-recs=%d\n",
+ VG_(fprintf)(fp, "desc: Option: --separate-recs=%d\n",
CLG_(clo).separate_recursions);
- my_fwrite(fd, buf, VG_(strlen)(buf));
- VG_(sprintf)(buf, "desc: Option: --separate-callers=%d\n",
+ VG_(fprintf)(fp, "desc: Option: --separate-callers=%d\n",
CLG_(clo).separate_callers);
- my_fwrite(fd, buf, VG_(strlen)(buf));
- VG_(sprintf)(buf, "desc: Option: --dump-bbs=%s\n",
+ VG_(fprintf)(fp, "desc: Option: --dump-bbs=%s\n",
CLG_(clo).dump_bbs ? "yes" : "no");
- my_fwrite(fd, buf, VG_(strlen)(buf));
- VG_(sprintf)(buf, "desc: Option: --separate-threads=%s\n",
+ VG_(fprintf)(fp, "desc: Option: --separate-threads=%s\n",
CLG_(clo).separate_threads ? "yes" : "no");
- my_fwrite(fd, buf, VG_(strlen)(buf));
#endif
- (*CLG_(cachesim).getdesc)(buf);
- my_fwrite(fd, buf, VG_(strlen)(buf));
+ (*CLG_(cachesim).dump_desc)(fp);
}
- VG_(sprintf)(buf, "\ndesc: Timerange: Basic block %llu - %llu\n",
+ VG_(fprintf)(fp, "\ndesc: Timerange: Basic block %llu - %llu\n",
bbs_done, CLG_(stat).bb_executions);
- my_fwrite(fd, buf, VG_(strlen)(buf));
- VG_(sprintf)(buf, "desc: Trigger: %s\n",
+ VG_(fprintf)(fp, "desc: Trigger: %s\n",
trigger ? trigger : "Program termination");
- my_fwrite(fd, buf, VG_(strlen)(buf));
#if 0
/* Output function specific config
fnc = fnc_table[i];
while (fnc) {
if (fnc->skip) {
- VG_(sprintf)(buf, "desc: Option: --fn-skip=%s\n", fnc->name);
- my_fwrite(fd, buf, VG_(strlen)(buf));
+ VG_(fprintf)(fp, "desc: Option: --fn-skip=%s\n", fnc->name);
}
if (fnc->dump_at_enter) {
- VG_(sprintf)(buf, "desc: Option: --fn-dump-at-enter=%s\n",
+ VG_(fprintf)(fp, "desc: Option: --fn-dump-at-enter=%s\n",
fnc->name);
- my_fwrite(fd, buf, VG_(strlen)(buf));
}
if (fnc->dump_at_leave) {
- VG_(sprintf)(buf, "desc: Option: --fn-dump-at-leave=%s\n",
+ VG_(fprintf)(fp, "desc: Option: --fn-dump-at-leave=%s\n",
fnc->name);
- my_fwrite(fd, buf, VG_(strlen)(buf));
}
if (fnc->separate_callers != CLG_(clo).separate_callers) {
- VG_(sprintf)(buf, "desc: Option: --separate-callers%d=%s\n",
+ VG_(fprintf)(fp, "desc: Option: --separate-callers%d=%s\n",
fnc->separate_callers, fnc->name);
- my_fwrite(fd, buf, VG_(strlen)(buf));
}
if (fnc->separate_recursions != CLG_(clo).separate_recursions) {
- VG_(sprintf)(buf, "desc: Option: --separate-recs%d=%s\n",
+ VG_(fprintf)(fp, "desc: Option: --separate-recs%d=%s\n",
fnc->separate_recursions, fnc->name);
- my_fwrite(fd, buf, VG_(strlen)(buf));
}
fnc = fnc->next;
}
#endif
/* "positions:" line */
- VG_(sprintf)(buf, "\npositions:%s%s%s\n",
+ VG_(fprintf)(fp, "\npositions:%s%s%s\n",
CLG_(clo).dump_instr ? " instr" : "",
CLG_(clo).dump_bb ? " bb" : "",
CLG_(clo).dump_line ? " line" : "");
- my_fwrite(fd, buf, VG_(strlen)(buf));
/* "events:" line */
HChar *evmap = CLG_(eventmapping_as_string)(CLG_(dumpmap));
- VG_(sprintf)(buf, "events: %s\n", evmap);
+ VG_(fprintf)(fp, "events: %s\n", evmap);
VG_(free)(evmap);
- my_fwrite(fd, buf, VG_(strlen)(buf));
/* summary lines */
sum = CLG_(get_eventset_cost)( CLG_(sets).full );
thr[t]->states.entry[0]->cost);
}
}
- fprint_cost_ln(fd, "summary: ", CLG_(dumpmap), sum);
+ fprint_cost_ln(fp, "summary: ", CLG_(dumpmap), sum);
/* all dumped cost will be added to total_fcc */
CLG_(init_cost_lz)( CLG_(sets).full, &dump_total_cost );
- my_fwrite(fd, "\n\n",2);
+ VG_(fprintf)(fp, "\n\n");
if (VG_(clo_verbosity) > 1)
VG_(message)(Vg_DebugMsg, "Dump to %s\n", filename);
- return fd;
+ return fp;
}
-static void close_dumpfile(int fd)
+static void close_dumpfile(VgFile *fp)
{
- if (fd <0) return;
+ if (fp == NULL) return;
- fprint_cost_ln(fd, "totals: ", CLG_(dumpmap),
+ fprint_cost_ln(fp, "totals: ", CLG_(dumpmap),
dump_total_cost);
- //fprint_fcc_ln(fd, "summary: ", &dump_total_fcc);
+ //fprint_fcc_ln(fp, "summary: ", &dump_total_fcc);
CLG_(add_cost_lz)(CLG_(sets).full,
&CLG_(total_cost), dump_total_cost);
- fwrite_flush();
- VG_(close)(fd);
+ VG_(fclose)(fp);
if (filename[0] == '.') {
if (-1 == VG_(rename) (filename, filename+1)) {
/* Helper for print_bbccs */
static const HChar* print_trigger;
-static HChar print_buf[BUF_LEN];
static void print_bbccs_of_thread(thread_info* ti)
{
CLG_DEBUG(1, "+ print_bbccs(tid %d)\n", CLG_(current_tid));
- Int print_fd = new_dumpfile(print_buf, CLG_(current_tid), print_trigger);
- if (print_fd <0) {
+ VgFile *print_fp = new_dumpfile(CLG_(current_tid), print_trigger);
+ if (print_fp == NULL) {
CLG_DEBUG(1, "- print_bbccs(tid %d): No output...\n", CLG_(current_tid));
return;
}
(lastFnPos.rec_index != (*p)->rec_index))) {
if (!CLG_(is_zero_cost)( CLG_(sets).full, ccSum[currSum].cost )) {
/* no need to switch buffers, as position is the same */
- fprint_apos(print_fd, &(ccSum[currSum].p), &lastAPos,
+ fprint_apos(print_fp, &(ccSum[currSum].p), &lastAPos,
lastFnPos.cxt->fn[0]->file);
- fprint_fcost(print_fd, &ccSum[currSum], &lastAPos);
+ fprint_fcost(print_fp, &ccSum[currSum], &lastAPos);
}
if (ccSum[currSum].p.file != lastFnPos.cxt->fn[0]->file) {
/* switch back to file of function */
- print_file(print_fd, "fe=", lastFnPos.cxt->fn[0]->file);
+ print_file(print_fp, "fe=", lastFnPos.cxt->fn[0]->file);
}
- my_fwrite(print_fd, "\n", 1);
+ VG_(fprintf)(print_fp, "\n");
}
if (*p == 0) break;
- if (print_fn_pos(print_fd, &lastFnPos, *p)) {
+ if (print_fn_pos(print_fp, &lastFnPos, *p)) {
/* new function */
init_apos(&lastAPos, 0, 0, (*p)->cxt->fn[0]->file);
if (CLG_(clo).dump_bbs) {
/* FIXME: Specify Object of BB if different to object of fn */
- int i, pos = 0;
+ int i;
ULong ecounter = (*p)->ecounter_sum;
- pos = VG_(sprintf)(print_buf, "bb=%#lx ", (*p)->bb->offset);
+ VG_(fprintf)(print_fp, "bb=%#lx ", (*p)->bb->offset);
for(i = 0; i<(*p)->bb->cjmp_count;i++) {
- pos += VG_(sprintf)(print_buf+pos, "%d %llu ",
+ VG_(fprintf)(print_fp, "%d %llu ",
(*p)->bb->jmp[i].instr,
ecounter);
ecounter -= (*p)->jmp[i].ecounter;
}
- VG_(sprintf)(print_buf+pos, "%d %llu\n",
+ VG_(fprintf)(print_fp, "%d %llu\n",
(*p)->bb->instr_count,
ecounter);
- my_fwrite(print_fd, print_buf, VG_(strlen)(print_buf));
}
- fprint_bbcc(print_fd, *p, &lastAPos);
+ fprint_bbcc(print_fp, *p, &lastAPos);
p++;
}
- close_dumpfile(print_fd);
+ close_dumpfile(print_fp);
VG_(free)(array);
/* set counters of last dump */