From: Frank Ch. Eigler Date: Wed, 2 Sep 2009 16:01:27 +0000 (-0400) Subject: PR10589: switch to kernel vscnprintf for _stp_{dbug,warn,error} calls in runtime X-Git-Tag: release-1.0~71 X-Git-Url: https://sourceware.org/git/?a=commitdiff_plain;h=e66aaecc057ef417d0dd1d0b94454f6704147e7f;p=systemtap.git PR10589: switch to kernel vscnprintf for _stp_{dbug,warn,error} calls in runtime _stp_vscnprintf is only suitable for calls from the script, with slightly different conventions (64-bit ints/pointers, extra formatting directives). * runtime/runtime.h (_stp_{dbug,warn,error}): Add __attribute__ format(printf). * runtime/io.c (_stp_vlog): Ditto. Use vscnprintf(). * runtime/sym.c (_stp_module_check): Remove hexdumping (%.*M) of mismatching buildids. Switch to _stp_warn from printk (KERN_WARNING). * translate.cxx, runtime/unwind.c: Numerous print formatting tweaks. --- diff --git a/runtime/io.c b/runtime/io.c index 8ddb53acd..687926fd8 100644 --- a/runtime/io.c +++ b/runtime/io.c @@ -22,6 +22,9 @@ #define ERR_STRING "ERROR: " enum code { INFO=0, WARN, ERROR, DBUG }; +static void _stp_vlog (enum code type, const char *func, int line, const char *fmt, va_list args) + __attribute ((format (printf, 4, 0))); + static void _stp_vlog (enum code type, const char *func, int line, const char *fmt, va_list args) { int num; @@ -38,7 +41,7 @@ static void _stp_vlog (enum code type, const char *func, int line, const char *f start = sizeof(ERR_STRING) - 1; } - num = _stp_vscnprintf (buf + start, STP_LOG_BUF_LEN - start - 1, fmt, args); + num = vscnprintf (buf + start, STP_LOG_BUF_LEN - start - 1, fmt, args); if (num + start) { if (buf[num + start - 1] != '\n') { buf[num + start] = '\n'; diff --git a/runtime/runtime.h b/runtime/runtime.h index c3bf501dc..064ded7b2 100644 --- a/runtime/runtime.h +++ b/runtime/runtime.h @@ -48,9 +48,9 @@ #define stp_for_each_cpu(cpu) for_each_cpu_mask((cpu), cpu_possible_map) #endif -static void _stp_dbug (const char *func, int line, const char *fmt, ...); -static void _stp_error (const char *fmt, ...); -static void _stp_warn (const char *fmt, ...); +static void _stp_dbug (const char *func, int line, const char *fmt, ...) __attribute__ ((format (printf, 3, 4))); +static void _stp_error (const char *fmt, ...) __attribute__ ((format (printf, 1, 2))); +static void _stp_warn (const char *fmt, ...) __attribute__ ((format (printf, 1, 2))); static void _stp_exit(void); diff --git a/runtime/sym.c b/runtime/sym.c index 30b6fc5ac..dd2235cce 100644 --- a/runtime/sym.c +++ b/runtime/sym.c @@ -276,24 +276,22 @@ static int _stp_module_check(void) continue; if (memcmp(m->build_id_bits, (unsigned char*) notes_addr, m->build_id_len)) { const char *basename; - basename = strrchr(m->path, '/'); if (basename) basename++; else basename = m->path; + #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,27) - _stp_error ("Build-id mismatch: \"%s\" %.*M" - " vs. \"%s\" %.*M\n", - m->name, m->build_id_len, notes_addr, - basename, m->build_id_len, m->build_id_bits); + _stp_error ("Build-id mismatch: \"%s\" vs. \"%s\"\n", + m->name, basename); return 1; #else /* This branch is a surrogate for kernels * affected by Fedora bug #465873. */ - printk(KERN_WARNING - "Build-id mismatch: \"%s\" vs. \"%s\"\n", - m->name, basename); + _stp_warn (KERN_WARNING + "Build-id mismatch: \"%s\" vs. \"%s\"\n", + m->name, basename); #endif } } /* end checking */ diff --git a/runtime/unwind.c b/runtime/unwind.c index cf0bc2f36..00108a391 100644 --- a/runtime/unwind.c +++ b/runtime/unwind.c @@ -121,7 +121,7 @@ static const u32 *cie_for_fde(const u32 *fde, void *unwind_data, if (*cie <= sizeof(*cie) + 4 || *cie >= fde[1] - sizeof(*fde) || (*cie & (sizeof(*cie) - 1)) || (cie[1] != 0xffffffff && cie[1] != 0)) { - dbug_unwind(1, "cie is not valid %lx %x %x %x\n", cie, *cie, fde[1], cie[1]); + dbug_unwind(1, "cie is not valid %lx %x %x %x\n", (unsigned long)cie, *cie, fde[1], cie[1]); return NULL; /* this is not a (valid) CIE */ } @@ -260,7 +260,7 @@ static int advance_loc(unsigned long delta, struct unwind_state *state) static void set_rule(uleb128_t reg, enum item_location where, uleb128_t value, struct unwind_state *state) { - dbug_unwind(1, "reg=%d, where=%d, value=%lx\n", reg, where, value); + dbug_unwind(1, "reg=%lx, where=%d, value=%lx\n", reg, where, value); if (reg < ARRAY_SIZE(state->regs)) { state->regs[reg].where = where; state->regs[reg].value = value; @@ -556,7 +556,7 @@ static u32 *_stp_search_unwind_hdr(unsigned long pc, num = read_pointer(&ptr, end, hdr[2]); if (num == 0 || num != (end - ptr) / (2 * tableSize) || (end - ptr) % (2 * tableSize)) { - dbug_unwind(1, "Bad num=%d end-ptr=%ld 2*tableSize=%d", num, end - ptr, 2 * tableSize); + dbug_unwind(1, "Bad num=%d end-ptr=%ld 2*tableSize=%d", num, (long)(end - ptr), 2 * tableSize); return NULL; } @@ -575,7 +575,7 @@ static u32 *_stp_search_unwind_hdr(unsigned long pc, if (num == 1 && (startLoc = adjustStartLoc(read_pointer(&ptr, ptr + tableSize, hdr[3]), m, s, hdr[3], 1)) != 0 && pc >= startLoc) fde = (void *)read_pointer(&ptr, ptr + tableSize, hdr[3]); - dbug_unwind(1, "returning fde=%lx startLoc=%lx", fde, startLoc); + dbug_unwind(1, "returning fde=%lx startLoc=%lx", (unsigned long) fde, startLoc); return fde; } @@ -602,7 +602,7 @@ static int unwind_frame(struct unwind_frame_info *frame, } fde = _stp_search_unwind_hdr(pc, m, s); - dbug_unwind(1, "%s: fde=%lx\n", m->name, fde); + dbug_unwind(1, "%s: fde=%lx\n", m->name, (unsigned long) fde); /* found the fde, now set startLoc and endLoc */ if (fde != NULL) { @@ -655,7 +655,8 @@ static int unwind_frame(struct unwind_frame_info *frame, } } - dbug_unwind(1, "cie=%lx fde=%lx startLoc=%lx endLoc=%lx, pc=%lx\n", cie, fde, startLoc, endLoc, pc); + dbug_unwind(1, "cie=%lx fde=%lx startLoc=%lx endLoc=%lx, pc=%lx\n", + (unsigned long) cie, (unsigned long)fde, (unsigned long) startLoc, (unsigned long) endLoc, pc); if (cie == NULL || fde == NULL) goto err; @@ -750,14 +751,15 @@ static int unwind_frame(struct unwind_frame_info *frame, if (STACK_LIMIT(startLoc) != STACK_LIMIT(endLoc)) { startLoc = min(STACK_LIMIT(cfa), cfa); endLoc = max(STACK_LIMIT(cfa), cfa); - dbug_unwind(1, "cfa startLoc=%p, endLoc=%p\n", (u64)startLoc, (u64)endLoc); + dbug_unwind(1, "cfa startLoc=%lx, endLoc=%lx\n", + (unsigned long)startLoc, (unsigned long)endLoc); } #ifndef CONFIG_64BIT # define CASES CASE(8); CASE(16); CASE(32) #else # define CASES CASE(8); CASE(16); CASE(32); CASE(64) #endif - dbug_unwind(1, "cie=%lx fde=%lx\n", cie, fde); + dbug_unwind(1, "cie=%lx fde=%lx\n", (unsigned long) cie, (unsigned long) fde); for (i = 0; i < ARRAY_SIZE(state.regs); ++i) { if (REG_INVALID(i)) { if (state.regs[i].where == Nowhere) diff --git a/translate.cxx b/translate.cxx index 56d6de4c4..65acd2cab 100644 --- a/translate.cxx +++ b/translate.cxx @@ -1189,7 +1189,7 @@ c_unparser::emit_module_init () o->newline() << "if (sizeof (struct context) <= 131072)"; o->newline(1) << "contexts = alloc_percpu (struct context);"; o->newline(-1) << "if (contexts == NULL) {"; - o->newline(1) << "_stp_error (\"percpu context (size %lu) allocation failed\", sizeof (struct context));"; + o->newline(1) << "_stp_error (\"percpu context (size %lu) allocation failed\", (unsigned long) sizeof (struct context));"; o->newline() << "rc = -ENOMEM;"; o->newline() << "goto out;"; o->newline(-1) << "}";