aboutsummaryrefslogtreecommitdiff
path: root/display_args.c
diff options
context:
space:
mode:
authorIan Wienand <ianw@ieee.org>2006-02-16 06:00:00 +0100
committerIan Wienand <ianw@debian.org>2006-02-16 06:00:00 +0100
commit3219f320604810532a4938dda8f9dfadb0e840f3 (patch)
treef2430182cafc250b2fcb9eb5c05730b2ce0d802f /display_args.c
parente1dd50cdd23a11bf7be6c81b3a2acbe35f19fdea (diff)
downloadltrace-3219f320604810532a4938dda8f9dfadb0e840f3.tar.gz
Some fixes...
* read_config_file.c: initialise pt stack argument to stop warning * summary.c: make show_summary() obey -C for demangaling function names
Diffstat (limited to 'display_args.c')
-rw-r--r--display_args.c273
1 files changed, 167 insertions, 106 deletions
diff --git a/display_args.c b/display_args.c
index 9a988e1..b8dc0f6 100644
--- a/display_args.c
+++ b/display_args.c
@@ -11,97 +11,110 @@
#include "options.h"
static int display_char(int what);
-static int display_string(enum tof type, struct process * proc, int arg_num);
-static int display_stringN(int arg2, enum tof type, struct process * proc, int arg_num);
-static int display_unknown(enum tof type, struct process * proc, int arg_num);
-static int display_format(enum tof type, struct process * proc, int arg_num);
+static int display_string(enum tof type, struct process *proc, int arg_num);
+static int display_stringN(int arg2, enum tof type, struct process *proc,
+ int arg_num);
+static int display_unknown(enum tof type, struct process *proc, int arg_num);
+static int display_format(enum tof type, struct process *proc, int arg_num);
int
-display_arg(enum tof type, struct process * proc, int arg_num, const struct complete_arg_type *at) {
+display_arg(enum tof type, struct process *proc, int arg_num,
+ const struct complete_arg_type *at)
+{
int tmp;
long arg;
- if(!at)
+ if (!at)
+ return display_unknown(type, proc, arg_num);
+ switch (at->at) {
+ case ARGTYPE_VOID:
+ return 0;
+ case ARGTYPE_INT:
+ return fprintf(output, "%d",
+ (int)gimme_arg(type, proc, arg_num));
+ case ARGTYPE_UINT:
+ return fprintf(output, "%u",
+ (unsigned)gimme_arg(type, proc, arg_num));
+ case ARGTYPE_LONG:
+ return fprintf(output, "%ld", gimme_arg(type, proc, arg_num));
+ case ARGTYPE_ULONG:
+ return fprintf(output, "%lu",
+ (unsigned long)gimme_arg(type, proc, arg_num));
+ case ARGTYPE_OCTAL:
+ return fprintf(output, "0%o",
+ (unsigned)gimme_arg(type, proc, arg_num));
+ case ARGTYPE_CHAR:
+ tmp = fprintf(output, "'");
+ tmp += display_char((int)gimme_arg(type, proc, arg_num));
+ tmp += fprintf(output, "'");
+ return tmp;
+ case ARGTYPE_ADDR:
+ arg = gimme_arg(type, proc, arg_num);
+ if (!arg) {
+ return fprintf(output, "NULL");
+ } else {
+ return fprintf(output, "%p", (void *)arg);
+ }
+ case ARGTYPE_FORMAT:
+ return display_format(type, proc, arg_num);
+ case ARGTYPE_STRING:
+ return display_string(type, proc, arg_num);
+ case ARGTYPE_STRINGN:
+ return display_stringN(at->argno, type, proc, arg_num);
+ case ARGTYPE_UNKNOWN:
+ default:
return display_unknown(type, proc, arg_num);
- switch(at->at) {
- case ARGTYPE_VOID:
- return 0;
- case ARGTYPE_INT:
- return fprintf(output, "%d", (int)gimme_arg(type, proc, arg_num));
- case ARGTYPE_UINT:
- return fprintf(output, "%u", (unsigned)gimme_arg(type, proc, arg_num));
- case ARGTYPE_LONG:
- return fprintf(output, "%ld", gimme_arg(type, proc, arg_num));
- case ARGTYPE_ULONG:
- return fprintf(output, "%lu", (unsigned long)gimme_arg(type, proc, arg_num));
- case ARGTYPE_OCTAL:
- return fprintf(output, "0%o", (unsigned)gimme_arg(type, proc, arg_num));
- case ARGTYPE_CHAR:
- tmp = fprintf(output, "'");
- tmp += display_char((int)gimme_arg(type, proc, arg_num));
- tmp += fprintf(output, "'");
- return tmp;
- case ARGTYPE_ADDR:
- arg = gimme_arg(type, proc, arg_num);
- if (!arg) {
- return fprintf(output, "NULL");
- } else {
- return fprintf(output, "%p", (void *)arg);
- }
- case ARGTYPE_FORMAT:
- return display_format(type, proc, arg_num);
- case ARGTYPE_STRING:
- return display_string(type, proc, arg_num);
- case ARGTYPE_STRINGN:
- return display_stringN(at->argno, type, proc, arg_num);
- case ARGTYPE_UNKNOWN:
- default:
- return display_unknown(type, proc, arg_num);
}
return fprintf(output, "?");
}
-static int
-display_char(int what) {
- switch(what) {
- case -1: return fprintf(output, "EOF");
- case '\r': return fprintf(output, "\\r");
- case '\n': return fprintf(output, "\\n");
- case '\t': return fprintf(output, "\\t");
- case '\b': return fprintf(output, "\\b");
- case '\\': return fprintf(output, "\\\\");
- default:
- if ((what<32) || (what>126)) {
- return fprintf(output, "\\%03o", (unsigned char)what);
- } else {
- return fprintf(output, "%c", what);
- }
+static int display_char(int what)
+{
+ switch (what) {
+ case -1:
+ return fprintf(output, "EOF");
+ case '\r':
+ return fprintf(output, "\\r");
+ case '\n':
+ return fprintf(output, "\\n");
+ case '\t':
+ return fprintf(output, "\\t");
+ case '\b':
+ return fprintf(output, "\\b");
+ case '\\':
+ return fprintf(output, "\\\\");
+ default:
+ if ((what < 32) || (what > 126)) {
+ return fprintf(output, "\\%03o", (unsigned char)what);
+ } else {
+ return fprintf(output, "%c", what);
+ }
}
}
-static int string_maxlength=INT_MAX;
+static int string_maxlength = INT_MAX;
#define MIN(a,b) (((a)<(b)) ? (a) : (b))
-static int
-display_string(enum tof type, struct process * proc, int arg_num) {
- void * addr;
- unsigned char * str1;
+static int display_string(enum tof type, struct process *proc, int arg_num)
+{
+ void *addr;
+ unsigned char *str1;
int i;
- int len=0;
+ int len = 0;
addr = (void *)gimme_arg(type, proc, arg_num);
if (!addr) {
return fprintf(output, "NULL");
}
- str1 = malloc(MIN(opt_s,string_maxlength)+3);
+ str1 = malloc(MIN(opt_s, string_maxlength) + 3);
if (!str1) {
return fprintf(output, "???");
}
- umovestr(proc, addr, MIN(opt_s,string_maxlength)+1, str1);
+ umovestr(proc, addr, MIN(opt_s, string_maxlength) + 1, str1);
len = fprintf(output, "\"");
- for(i=0; i<MIN(opt_s,string_maxlength); i++) {
+ for (i = 0; i < MIN(opt_s, string_maxlength); i++) {
if (str1[i]) {
len += display_char(str1[i]);
} else {
@@ -117,47 +130,48 @@ display_string(enum tof type, struct process * proc, int arg_num) {
}
static int
-display_stringN(int arg2, enum tof type, struct process * proc, int arg_num) {
+display_stringN(int arg2, enum tof type, struct process *proc, int arg_num)
+{
int a;
- string_maxlength=gimme_arg(type, proc, arg2-1);
+ string_maxlength = gimme_arg(type, proc, arg2 - 1);
a = display_string(type, proc, arg_num);
- string_maxlength=INT_MAX;
+ string_maxlength = INT_MAX;
return a;
}
-static int
-display_unknown(enum tof type, struct process * proc, int arg_num) {
+static int display_unknown(enum tof type, struct process *proc, int arg_num)
+{
long tmp;
tmp = gimme_arg(type, proc, arg_num);
- if (tmp<1000000 && tmp>-1000000) {
+ if (tmp < 1000000 && tmp > -1000000) {
return fprintf(output, "%ld", tmp);
} else {
return fprintf(output, "%p", (void *)tmp);
}
}
-static int
-display_format(enum tof type, struct process * proc, int arg_num) {
- void * addr;
- unsigned char * str1;
+static int display_format(enum tof type, struct process *proc, int arg_num)
+{
+ void *addr;
+ unsigned char *str1;
int i;
- int len=0;
+ int len = 0;
addr = (void *)gimme_arg(type, proc, arg_num);
if (!addr) {
return fprintf(output, "NULL");
}
- str1 = malloc(MIN(opt_s,string_maxlength)+3);
+ str1 = malloc(MIN(opt_s, string_maxlength) + 3);
if (!str1) {
return fprintf(output, "???");
}
- umovestr(proc, addr, MIN(opt_s,string_maxlength)+1, str1);
+ umovestr(proc, addr, MIN(opt_s, string_maxlength) + 1, str1);
len = fprintf(output, "\"");
- for(i=0; len<MIN(opt_s,string_maxlength)+1; i++) {
+ for (i = 0; len < MIN(opt_s, string_maxlength) + 1; i++) {
if (str1[i]) {
len += display_char(str1[i]);
} else {
@@ -168,67 +182,114 @@ display_format(enum tof type, struct process * proc, int arg_num) {
if (str1[i] && (opt_s <= string_maxlength)) {
len += fprintf(output, "...");
}
- for(i=0; str1[i]; i++) {
- if (str1[i]=='%') {
+ for (i = 0; str1[i]; i++) {
+ if (str1[i] == '%') {
int is_long = 0;
- while(1) {
+ while (1) {
unsigned char c = str1[++i];
if (c == '%') {
break;
} else if (!c) {
break;
- } else if (strchr ("lzZtj", c)) {
+ } else if (strchr("lzZtj", c)) {
is_long++;
if (c == 'j')
is_long++;
- if (is_long > 1 && sizeof (long) < sizeof (long long)) {
+ if (is_long > 1
+ && sizeof(long) <
+ sizeof(long long)) {
len += fprintf(output, ", ...");
- str1[i+1]='\0';
+ str1[i + 1] = '\0';
break;
}
- } else if (c=='d' || c=='i') {
+ } else if (c == 'd' || c == 'i') {
if (is_long)
- len += fprintf(output, ", %d", (int)gimme_arg(type, proc, ++arg_num));
+ len +=
+ fprintf(output, ", %d",
+ (int)gimme_arg(type,
+ proc,
+ ++arg_num));
else
- len += fprintf(output, ", %ld", gimme_arg(type, proc, ++arg_num));
+ len +=
+ fprintf(output, ", %ld",
+ gimme_arg(type,
+ proc,
+ ++arg_num));
break;
- } else if (c=='u') {
+ } else if (c == 'u') {
if (is_long)
- len += fprintf(output, ", %u", (int)gimme_arg(type, proc, ++arg_num));
+ len +=
+ fprintf(output, ", %u",
+ (int)gimme_arg(type,
+ proc,
+ ++arg_num));
else
- len += fprintf(output, ", %lu", gimme_arg(type, proc, ++arg_num));
+ len +=
+ fprintf(output, ", %lu",
+ gimme_arg(type,
+ proc,
+ ++arg_num));
break;
- } else if (c=='o') {
+ } else if (c == 'o') {
if (is_long)
- len += fprintf(output, ", 0%o", (int)gimme_arg(type, proc, ++arg_num));
+ len +=
+ fprintf(output, ", 0%o",
+ (int)gimme_arg(type,
+ proc,
+ ++arg_num));
else
- len += fprintf(output, ", 0%lo", gimme_arg(type, proc, ++arg_num));
+ len +=
+ fprintf(output, ", 0%lo",
+ gimme_arg(type,
+ proc,
+ ++arg_num));
break;
- } else if (c=='x' || c=='X') {
+ } else if (c == 'x' || c == 'X') {
if (is_long)
- len += fprintf(output, ", %#x", (int)gimme_arg(type, proc, ++arg_num));
+ len +=
+ fprintf(output, ", %#x",
+ (int)gimme_arg(type,
+ proc,
+ ++arg_num));
else
- len += fprintf(output, ", %#lx", gimme_arg(type, proc, ++arg_num));
+ len +=
+ fprintf(output, ", %#lx",
+ gimme_arg(type,
+ proc,
+ ++arg_num));
break;
} else if (strchr("eEfFgGaACS", c)
- || (is_long && (c=='c' || c=='s'))) {
+ || (is_long
+ && (c == 'c' || c == 's'))) {
len += fprintf(output, ", ...");
- str1[i+1]='\0';
+ str1[i + 1] = '\0';
break;
- } else if (c=='c') {
+ } else if (c == 'c') {
len += fprintf(output, ", '");
- len += display_char((int)gimme_arg(type, proc, ++arg_num));
+ len += display_char((int)
+ gimme_arg(type,
+ proc,
+ ++arg_num));
len += fprintf(output, "'");
break;
- } else if (c=='s') {
+ } else if (c == 's') {
len += fprintf(output, ", ");
- len += display_string(type, proc, ++arg_num);
+ len +=
+ display_string(type, proc,
+ ++arg_num);
break;
- } else if (c=='p' || c=='n') {
- len += fprintf(output, ", %p", (void *)gimme_arg(type, proc, ++arg_num));
+ } else if (c == 'p' || c == 'n') {
+ len +=
+ fprintf(output, ", %p",
+ (void *)gimme_arg(type,
+ proc,
+ ++arg_num));
break;
- } else if (c=='*') {
- len += fprintf(output, ", %d", (int)gimme_arg(type, proc, ++arg_num));
+ } else if (c == '*') {
+ len +=
+ fprintf(output, ", %d",
+ (int)gimme_arg(type, proc,
+ ++arg_num));
}
}
}