2 * Copyright (c) 2003,2004 The DragonFly Project. All rights reserved.
4 * This code is derived from software contributed to The DragonFly Project
5 * by Matthew Dillon <dillon@backplane.com>
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
17 * 3. Neither the name of The DragonFly Project nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific, prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25 * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26 * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
27 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
29 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
30 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
31 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 * $DragonFly: src/sbin/jscan/dump_debug.c,v 1.3 2005/07/05 00:26:03 dillon Exp $
39 static void dump_debug_stream(struct jstream *js);
40 static int dump_debug_subrecord(struct jstream *js, off_t *off,
41 off_t recsize, int level);
44 dump_debug(struct jfile *jf)
48 while ((js = jscan_stream(jf)) != NULL) {
49 dump_debug_stream(js);
55 dump_debug_stream(struct jstream *js)
57 struct journal_rawrecbeg head;
60 jsread(js, 0, &head, sizeof(head));
62 sid = head.streamid & JREC_STREAMID_MASK;
63 printf("STREAM %04x {\n", (int)(u_int16_t)head.streamid);
64 if (sid >= JREC_STREAMID_JMIN && sid < JREC_STREAMID_JMAX) {
65 off_t off = sizeof(head);
67 dump_debug_subrecord(js, &off,
68 js->js_normalized_total - sizeof(head),
71 switch(head.streamid & JREC_STREAMID_MASK) {
72 case JREC_STREAMID_SYNCPT & JREC_STREAMID_MASK:
75 case JREC_STREAMID_PAD & JREC_STREAMID_MASK:
78 case JREC_STREAMID_DISCONT & JREC_STREAMID_MASK:
81 case JREC_STREAMID_ANNOTATE & JREC_STREAMID_MASK:
82 printf(" ANNOTATION\n");
93 dump_debug_subrecord(struct jstream *js, off_t *off, off_t recsize, int level)
95 struct journal_subrecord sub;
102 while (recsize > 0) {
103 if ((error = jsread(js, base, &sub, sizeof(sub))) != 0) {
106 printf("%*.*s", level * 4, level * 4, "");
107 printf("@%lld ", base);
108 printf("RECORD %s [%04x/%d]", type_to_name(sub.rectype),
109 (int)(u_int16_t)sub.rectype, sub.recsize);
110 if (sub.recsize == -1) {
111 if ((sub.rectype & JMASK_NESTED) == 0) {
112 printf("Record size of -1 only works for nested records\n");
116 payload = 0x7FFFFFFF;
117 subsize = 0x7FFFFFFF;
119 payload = sub.recsize - sizeof(sub);
120 subsize = (sub.recsize + 7) & ~7;
122 if (sub.rectype & JMASK_NESTED) {
125 *off = base + sizeof(sub);
126 error = dump_debug_subrecord(js, off, payload, level + 1);
128 printf("%*.*s}\n", level * 4, level * 4, "");
129 } else if (sub.rectype & JMASK_SUBRECORD) {
130 printf(" DATA (%d)", payload);
131 error = dump_debug_payload(sub.rectype, js, base + sizeof(sub), payload, level);
132 *off = base + sizeof(sub) + payload;
135 printf("[%d bytes of unknown content]\n", sub.recsize);
139 if (sub.recsize == -1) {
140 recsize -= ((*off + 7) & ~7) - base;
141 base = (*off + 7) & ~7;
144 subsize = sizeof(sub);
148 if (sub.rectype & JMASK_LAST)
156 dump_debug_payload(int16_t rectype, struct jstream *js, off_t off,
157 int recsize, int level)
159 enum { DT_NONE, DT_STRING, DT_DEC, DT_HEX, DT_OCT,
160 DT_DATA, DT_TIMESTAMP } dt = DT_DATA;
166 error = jsreadp(js, off, (const void **)&buf, recsize);
170 switch(rectype & ~JMASK_LAST) {
206 case JLEAF_RESERVED_0F:
208 case JLEAF_SYMLINKDATA:
251 for (i = 0; i < recsize; ++i)
252 stringout(stdout, buf[i], 1);
258 printf(" %d", (int)*(const u_int8_t *)buf);
261 printf(" %d", (int)*(const u_int16_t *)buf);
264 printf(" %d", (int)*(const u_int32_t *)buf);
267 printf(" %lld", (int64_t)*(const u_int64_t *)buf);
277 printf(" 0x%02x", (int)*(const u_int8_t *)buf);
280 printf(" 0x%04x", (int)*(const u_int16_t *)buf);
283 printf(" 0x%08x", (int)*(const u_int32_t *)buf);
286 printf(" 0x%016llx", (int64_t)*(const u_int64_t *)buf);
296 printf(" %03o", (int)*(const u_int8_t *)buf);
299 printf(" %06o", (int)*(const u_int16_t *)buf);
302 printf(" %011o", (int)*(const u_int32_t *)buf);
305 printf(" %022llo", (int64_t)*(const u_int64_t *)buf);
315 time_t t = ((const struct timespec *)buf)->tv_sec;
319 strftime(outbuf, sizeof(outbuf), " <%d-%b-%Y %H:%M:%S>", tp);
320 printf("%s", outbuf);
326 for (i = 0; i < recsize; ++i)
327 printf(" %02x", (int)(unsigned char)buf[i]);
329 for (i = 0; i < recsize; ++i)
330 stringout(stdout, buf[i], 0);
334 for (i = 0; i < recsize; i += 16) {
335 printf("%*.*s", level * 4 + 4, level * 4 + 4, "");
336 for (j = i; j < i + 16 && j < recsize; ++j)
337 printf(" %02x", (int)(unsigned char)buf[j]);
338 for (; j < i + 16; ++j)
341 for (j = i; j < i + 16 && j < recsize; ++j)
342 stringout(stdout, buf[j], 0);
345 printf("%*.*s}", level * 4, level * 4, "");