summaryrefslogtreecommitdiff
path: root/source/compiler/asldebug.c
diff options
context:
space:
mode:
authorJung-uk Kim <jkim@FreeBSD.org>2017-08-31 17:21:06 +0000
committerJung-uk Kim <jkim@FreeBSD.org>2017-08-31 17:21:06 +0000
commit0810e26699e1b40b9384eca2137be6155de0a5ba (patch)
tree2f9f57dbc41ae321c10f66c7d7985e328edbdec8 /source/compiler/asldebug.c
parent834d4c5613e9c57c0b9fba46fa717fd7fb9d5891 (diff)
Notes
Diffstat (limited to 'source/compiler/asldebug.c')
-rw-r--r--source/compiler/asldebug.c87
1 files changed, 86 insertions, 1 deletions
diff --git a/source/compiler/asldebug.c b/source/compiler/asldebug.c
index b0b386408498..684e222485bf 100644
--- a/source/compiler/asldebug.c
+++ b/source/compiler/asldebug.c
@@ -165,6 +165,10 @@ UtDumpParseOpName (
UINT32 Level,
UINT32 DataLength);
+static char *
+UtCreateEscapeSequences (
+ char *InString);
+
/*******************************************************************************
*
@@ -272,7 +276,6 @@ UtDumpStringOp (
String = Op->Asl.Value.String;
-
if (Op->Asl.ParseOpcode != PARSEOP_STRING_LITERAL)
{
/*
@@ -294,6 +297,8 @@ UtDumpStringOp (
return;
}
+ String = UtCreateEscapeSequences (String);
+
/* Emit the ParseOp name, leaving room for the string */
UtDumpParseOpName (Op, Level, strlen (String));
@@ -303,6 +308,86 @@ UtDumpStringOp (
/*******************************************************************************
*
+ * FUNCTION: UtCreateEscapeSequences
+ *
+ * PARAMETERS: InString - ASCII string to be expanded
+ *
+ * RETURN: Expanded string
+ *
+ * DESCRIPTION: Expand all non-printable ASCII bytes (0-0x1F) to escape
+ * sequences. For example, hex 14 becomes \x14
+ *
+ * NOTE: Since this function is used for debug output only, it does
+ * not attempt to translate into the "known" escape sequences
+ * such as \a, \f, \t, etc.
+ *
+ ******************************************************************************/
+
+static char *
+UtCreateEscapeSequences (
+ char *InString)
+{
+ char *String = InString;
+ char *OutString;
+ char *OutStringPtr;
+ UINT32 InStringLength = 0;
+ UINT32 EscapeCount = 0;
+
+
+ /*
+ * Determine up front how many escapes are within the string.
+ * Obtain the input string length while doing so.
+ */
+ while (*String)
+ {
+ if ((*String <= 0x1F) || (*String >= 0x7F))
+ {
+ EscapeCount++;
+ }
+
+ InStringLength++;
+ String++;
+ }
+
+ if (!EscapeCount)
+ {
+ return (InString); /* No escapes, nothing to do */
+ }
+
+ /* New string buffer, 3 extra chars per escape (4 total) */
+
+ OutString = UtLocalCalloc (InStringLength + (EscapeCount * 3));
+ OutStringPtr = OutString;
+
+ /* Convert non-ascii or non-printable chars to escape sequences */
+
+ while (*InString)
+ {
+ if ((*InString <= 0x1F) || (*InString >= 0x7F))
+ {
+ /* Insert a \x hex escape sequence */
+
+ OutStringPtr[0] = '\\';
+ OutStringPtr[1] = 'x';
+ OutStringPtr[2] = AcpiUtHexToAsciiChar (*InString, 4);
+ OutStringPtr[3] = AcpiUtHexToAsciiChar (*InString, 0);
+ OutStringPtr += 4;
+ }
+ else /* Normal ASCII character */
+ {
+ *OutStringPtr = *InString;
+ OutStringPtr++;
+ }
+
+ InString++;
+ }
+
+ return (OutString);
+}
+
+
+/*******************************************************************************
+ *
* FUNCTION: UtDumpBasicOp
*
* PARAMETERS: Op - Current parse op