1 /******************************************************************************
3 * Module Name: dbhistry - debugger HISTORY command
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2013, Intel Corp.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions, and the following disclaimer,
16 * without modification.
17 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 * substantially similar to the "NO WARRANTY" disclaimer below
19 * ("Disclaimer") and any redistribution must be conditioned upon
20 * including a substantially similar Disclaimer requirement for further
21 * binary redistribution.
22 * 3. Neither the names of the above-listed copyright holders nor the names
23 * of any contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
26 * Alternatively, this software may be distributed under the terms of the
27 * GNU General Public License ("GPL") version 2 as published by the Free
28 * Software Foundation.
31 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 * POSSIBILITY OF SUCH DAMAGES.
45 #include <contrib/dev/acpica/include/acpi.h>
46 #include <contrib/dev/acpica/include/accommon.h>
47 #include <contrib/dev/acpica/include/acdebug.h>
51 #define _COMPONENT ACPI_CA_DEBUGGER
52 ACPI_MODULE_NAME ("dbhistry")
55 #define HI_NO_HISTORY 0
56 #define HI_RECORD_HISTORY 1
57 #define HISTORY_SIZE 40
60 typedef struct HistoryInfo
68 static HISTORY_INFO AcpiGbl_HistoryBuffer[HISTORY_SIZE];
69 static UINT16 AcpiGbl_LoHistory = 0;
70 static UINT16 AcpiGbl_NumHistory = 0;
71 static UINT16 AcpiGbl_NextHistoryIndex = 0;
72 static UINT32 AcpiGbl_NextCmdNum = 1;
75 /*******************************************************************************
77 * FUNCTION: AcpiDbAddToHistory
79 * PARAMETERS: CommandLine - Command to add
83 * DESCRIPTION: Add a command line to the history buffer.
85 ******************************************************************************/
94 /* Put command into the next available slot */
96 CmdLen = (UINT16) ACPI_STRLEN (CommandLine);
97 if (AcpiGbl_HistoryBuffer[AcpiGbl_NextHistoryIndex].Command != NULL)
99 BufferLen = (UINT16) ACPI_STRLEN (
100 AcpiGbl_HistoryBuffer[AcpiGbl_NextHistoryIndex].Command);
101 if (CmdLen > BufferLen)
103 AcpiOsFree (AcpiGbl_HistoryBuffer[AcpiGbl_NextHistoryIndex].
105 AcpiGbl_HistoryBuffer[AcpiGbl_NextHistoryIndex].Command =
106 AcpiOsAllocate (CmdLen + 1);
111 AcpiGbl_HistoryBuffer[AcpiGbl_NextHistoryIndex].Command =
112 AcpiOsAllocate (CmdLen + 1);
115 ACPI_STRCPY (AcpiGbl_HistoryBuffer[AcpiGbl_NextHistoryIndex].Command,
118 AcpiGbl_HistoryBuffer[AcpiGbl_NextHistoryIndex].CmdNum =
123 if ((AcpiGbl_NumHistory == HISTORY_SIZE) &&
124 (AcpiGbl_NextHistoryIndex == AcpiGbl_LoHistory))
127 if (AcpiGbl_LoHistory >= HISTORY_SIZE)
129 AcpiGbl_LoHistory = 0;
133 AcpiGbl_NextHistoryIndex++;
134 if (AcpiGbl_NextHistoryIndex >= HISTORY_SIZE)
136 AcpiGbl_NextHistoryIndex = 0;
139 AcpiGbl_NextCmdNum++;
140 if (AcpiGbl_NumHistory < HISTORY_SIZE)
142 AcpiGbl_NumHistory++;
147 /*******************************************************************************
149 * FUNCTION: AcpiDbDisplayHistory
155 * DESCRIPTION: Display the contents of the history buffer
157 ******************************************************************************/
160 AcpiDbDisplayHistory (
167 HistoryIndex = AcpiGbl_LoHistory;
169 /* Dump entire history buffer */
171 for (i = 0; i < AcpiGbl_NumHistory; i++)
173 if (AcpiGbl_HistoryBuffer[HistoryIndex].Command)
175 AcpiOsPrintf ("%3ld %s\n",
176 AcpiGbl_HistoryBuffer[HistoryIndex].CmdNum,
177 AcpiGbl_HistoryBuffer[HistoryIndex].Command);
181 if (HistoryIndex >= HISTORY_SIZE)
189 /*******************************************************************************
191 * FUNCTION: AcpiDbGetFromHistory
193 * PARAMETERS: CommandNumArg - String containing the number of the
194 * command to be retrieved
196 * RETURN: Pointer to the retrieved command. Null on error.
198 * DESCRIPTION: Get a command from the history buffer
200 ******************************************************************************/
203 AcpiDbGetFromHistory (
211 if (CommandNumArg == NULL)
213 CmdNum = AcpiGbl_NextCmdNum - 1;
218 CmdNum = ACPI_STRTOUL (CommandNumArg, NULL, 0);
221 /* Search history buffer */
223 HistoryIndex = AcpiGbl_LoHistory;
224 for (i = 0; i < AcpiGbl_NumHistory; i++)
226 if (AcpiGbl_HistoryBuffer[HistoryIndex].CmdNum == CmdNum)
228 /* Found the command, return it */
230 return (AcpiGbl_HistoryBuffer[HistoryIndex].Command);
235 if (HistoryIndex >= HISTORY_SIZE)
241 AcpiOsPrintf ("Invalid history number: %u\n", HistoryIndex);
245 #endif /* ACPI_DEBUGGER */