1
/* $Id: VBoxPrintHexDump.c $ */
3
* VBoxPrintHex.c - Implementation of the VBoxPrintHex() debug logging routine.
7
* Copyright (C) 2009-2010 Sun Microsystems, Inc.
9
* This file is part of VirtualBox Open Source Edition (OSE), as
10
* available from http://www.virtualbox.org. This file is free software;
11
* you can redistribute it and/or modify it under the terms of the GNU
12
* General Public License (GPL) as published by the Free Software
13
* Foundation, in version 2 as it comes in the "COPYING" file of the
14
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
17
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
18
* Clara, CA 95054 USA or visit http://www.sun.com if you need
19
* additional information or have any questions.
24
/*******************************************************************************
26
*******************************************************************************/
27
#include "VBoxDebugLib.h"
29
#include <iprt/ctype.h>
35
* @param ch The char to print.
37
DECLINLINE(int) vboxPrintHexDumpChar(int ch)
39
ASMOutU8(EFI_DEBUG_PORT, (uint8_t)ch);
45
* Prints a hex dump the specified memory block.
47
* @returns Number of bytes printed.
49
* @param pv The memory to dump.
50
* @param cb Number of bytes to dump.
52
size_t VBoxPrintHexDump(const void *pv, size_t cb)
54
size_t cchPrinted = 0;
55
uint8_t const *pb = (uint8_t const *)pv;
61
cchPrinted += VBoxPrintHex((uintptr_t)pb, sizeof(pb));
62
cchPrinted += VBoxPrintString(" ");
64
/* the hex bytes value. */
65
for (i = 0; i < 16; i++)
67
cchPrinted += vboxPrintHexDumpChar(i == 7 ? '-' : ' ');
69
cchPrinted += VBoxPrintHex(pb[i], 1);
71
cchPrinted += VBoxPrintString(" ");
74
/* the printable chars */
75
cchPrinted += VBoxPrintString(" ");
76
for (i = 0; i < 16 && i < cb; i++)
77
cchPrinted += vboxPrintHexDumpChar(pb[i] == ' '
79
: RT_C_IS_GRAPH(pb[i])
83
/* finally, the new line. */
84
cchPrinted += vboxPrintHexDumpChar('\n');