VirtualBox

source: vbox/trunk/src/VBox/Debugger/DBGCCmdWorkers.cpp@ 41780

Last change on this file since 41780 was 35673, checked in by vboxsync, 14 years ago

Debugger Console: Some cleanups.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 5.9 KB
Line 
1/* $Id: DBGCCmdWorkers.cpp 35673 2011-01-24 10:15:44Z vboxsync $ */
2/** @file
3 * DBGC - Debugger Console, Command Worker Routines.
4 */
5
6/*
7 * Copyright (C) 2006-2011 Oracle Corporation
8 *
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.
16 */
17
18/*******************************************************************************
19* Header Files *
20*******************************************************************************/
21#define LOG_GROUP LOG_GROUP_DBGC
22#include <VBox/dbg.h>
23#include <VBox/vmm/dbgf.h>
24#include <VBox/param.h>
25#include <VBox/err.h>
26#include <VBox/log.h>
27
28#include <iprt/alloc.h>
29#include <iprt/string.h>
30#include <iprt/assert.h>
31
32#include "DBGCInternal.h"
33
34
35
36
37//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//
38//
39//
40// B r e a k p o i n t M a n a g e m e n t
41//
42//
43//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//
44
45
46/**
47 * Adds a breakpoint to the DBGC breakpoint list.
48 */
49int dbgcBpAdd(PDBGC pDbgc, RTUINT iBp, const char *pszCmd)
50{
51 /*
52 * Check if it already exists.
53 */
54 PDBGCBP pBp = dbgcBpGet(pDbgc, iBp);
55 if (pBp)
56 return VERR_DBGC_BP_EXISTS;
57
58 /*
59 * Add the breakpoint.
60 */
61 if (pszCmd)
62 pszCmd = RTStrStripL(pszCmd);
63 size_t cchCmd = pszCmd ? strlen(pszCmd) : 0;
64 pBp = (PDBGCBP)RTMemAlloc(RT_OFFSETOF(DBGCBP, szCmd[cchCmd + 1]));
65 if (!pBp)
66 return VERR_NO_MEMORY;
67 if (cchCmd)
68 memcpy(pBp->szCmd, pszCmd, cchCmd + 1);
69 else
70 pBp->szCmd[0] = '\0';
71 pBp->cchCmd = cchCmd;
72 pBp->iBp = iBp;
73 pBp->pNext = pDbgc->pFirstBp;
74 pDbgc->pFirstBp = pBp;
75
76 return VINF_SUCCESS;
77}
78
79/**
80 * Updates the a breakpoint.
81 *
82 * @returns VBox status code.
83 * @param pDbgc The DBGC instance.
84 * @param iBp The breakpoint to update.
85 * @param pszCmd The new command.
86 */
87int dbgcBpUpdate(PDBGC pDbgc, RTUINT iBp, const char *pszCmd)
88{
89 /*
90 * Find the breakpoint.
91 */
92 PDBGCBP pBp = dbgcBpGet(pDbgc, iBp);
93 if (!pBp)
94 return VERR_DBGC_BP_NOT_FOUND;
95
96 /*
97 * Do we need to reallocate?
98 */
99 if (pszCmd)
100 pszCmd = RTStrStripL(pszCmd);
101 if (!pszCmd || !*pszCmd)
102 pBp->szCmd[0] = '\0';
103 else
104 {
105 size_t cchCmd = strlen(pszCmd);
106 if (strlen(pBp->szCmd) >= cchCmd)
107 {
108 memcpy(pBp->szCmd, pszCmd, cchCmd + 1);
109 pBp->cchCmd = cchCmd;
110 }
111 else
112 {
113 /*
114 * Yes, let's do it the simple way...
115 */
116 int rc = dbgcBpDelete(pDbgc, iBp);
117 AssertRC(rc);
118 return dbgcBpAdd(pDbgc, iBp, pszCmd);
119 }
120 }
121 return VINF_SUCCESS;
122}
123
124
125/**
126 * Deletes a breakpoint.
127 *
128 * @returns VBox status code.
129 * @param pDbgc The DBGC instance.
130 * @param iBp The breakpoint to delete.
131 */
132int dbgcBpDelete(PDBGC pDbgc, RTUINT iBp)
133{
134 /*
135 * Search thru the list, when found unlink and free it.
136 */
137 PDBGCBP pBpPrev = NULL;
138 PDBGCBP pBp = pDbgc->pFirstBp;
139 for (; pBp; pBp = pBp->pNext)
140 {
141 if (pBp->iBp == iBp)
142 {
143 if (pBpPrev)
144 pBpPrev->pNext = pBp->pNext;
145 else
146 pDbgc->pFirstBp = pBp->pNext;
147 RTMemFree(pBp);
148 return VINF_SUCCESS;
149 }
150 pBpPrev = pBp;
151 }
152
153 return VERR_DBGC_BP_NOT_FOUND;
154}
155
156
157/**
158 * Get a breakpoint.
159 *
160 * @returns Pointer to the breakpoint.
161 * @returns NULL if the breakpoint wasn't found.
162 * @param pDbgc The DBGC instance.
163 * @param iBp The breakpoint to get.
164 */
165PDBGCBP dbgcBpGet(PDBGC pDbgc, RTUINT iBp)
166{
167 /*
168 * Enumerate the list.
169 */
170 PDBGCBP pBp = pDbgc->pFirstBp;
171 for (; pBp; pBp = pBp->pNext)
172 if (pBp->iBp == iBp)
173 return pBp;
174 return NULL;
175}
176
177
178/**
179 * Executes the command of a breakpoint.
180 *
181 * @returns VINF_DBGC_BP_NO_COMMAND if there is no command associated with the breakpoint.
182 * @returns VERR_DBGC_BP_NOT_FOUND if the breakpoint wasn't found.
183 * @returns VERR_BUFFER_OVERFLOW if the is not enough space in the scratch buffer for the command.
184 * @returns VBox status code from dbgcEvalCommand() otherwise.
185 * @param pDbgc The DBGC instance.
186 * @param iBp The breakpoint to execute.
187 */
188int dbgcBpExec(PDBGC pDbgc, RTUINT iBp)
189{
190 /*
191 * Find the breakpoint.
192 */
193 PDBGCBP pBp = dbgcBpGet(pDbgc, iBp);
194 if (!pBp)
195 return VERR_DBGC_BP_NOT_FOUND;
196
197 /*
198 * Anything to do?
199 */
200 if (!pBp->cchCmd)
201 return VINF_DBGC_BP_NO_COMMAND;
202
203 /*
204 * Execute the command.
205 * This means copying it to the scratch buffer and process it as if it
206 * were user input. We must save and restore the state of the scratch buffer.
207 */
208 /* Save the scratch state. */
209 char *pszScratch = pDbgc->pszScratch;
210 unsigned iArg = pDbgc->iArg;
211
212 /* Copy the command to the scratch buffer. */
213 size_t cbScratch = sizeof(pDbgc->achScratch) - (pDbgc->pszScratch - &pDbgc->achScratch[0]);
214 if (pBp->cchCmd >= cbScratch)
215 return VERR_BUFFER_OVERFLOW;
216 memcpy(pDbgc->pszScratch, pBp->szCmd, pBp->cchCmd + 1);
217
218 /* Execute the command. */
219 pDbgc->pszScratch = pDbgc->pszScratch + pBp->cchCmd + 1;
220 int rc = dbgcEvalCommand(pDbgc, pszScratch, pBp->cchCmd, false /* fNoExecute */);
221
222 /* Restore the scratch state. */
223 pDbgc->iArg = iArg;
224 pDbgc->pszScratch = pszScratch;
225
226 return rc;
227}
228
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette