L4Re – L4 Runtime Environment
debugger.h
Go to the documentation of this file.
1 #pragma once
7 /*
8  * (c) 2008-2011 Adam Lackorzynski <adam@os.inf.tu-dresden.de>,
9  * Alexander Warg <warg@os.inf.tu-dresden.de>
10  * economic rights: Technische Universität Dresden (Germany)
11  *
12  * This file is part of TUD:OS and distributed under the terms of the
13  * GNU General Public License 2.
14  * Please see the COPYING-GPL-2 file for details.
15  *
16  * As a special exception, you may use this file as part of a free software
17  * library without restriction. Specifically, if other files instantiate
18  * templates or use macros or inline functions from this file, or you compile
19  * this file and link it with other files to produce an executable, this
20  * file does not by itself cause the resulting executable to be covered by
21  * the GNU General Public License. This exception does not however
22  * invalidate any other reasons why the executable file might be covered by
23  * the GNU General Public License.
24  */
25 
26 #include <l4/sys/compiler.h>
27 #include <l4/sys/utcb.h>
28 #include <l4/sys/ipc.h>
29 
53 L4_INLINE l4_msgtag_t
55 
59 L4_INLINE l4_msgtag_t
60 l4_debugger_set_object_name_u(l4_cap_idx_t cap, const char *name, l4_utcb_t *utcb) L4_NOTHROW;
61 
73 L4_INLINE l4_msgtag_t
75  char *name, unsigned size) L4_NOTHROW;
76 
80 L4_INLINE l4_msgtag_t
81 l4_debugger_get_object_name_u(l4_cap_idx_t cap, unsigned id,
82  char *name, unsigned size,
83  l4_utcb_t *utcb) L4_NOTHROW;
84 
96 L4_INLINE unsigned long
98 
102 L4_INLINE unsigned long
103 l4_debugger_global_id_u(l4_cap_idx_t cap, l4_utcb_t *utcb) L4_NOTHROW;
104 
117 L4_INLINE unsigned long
119 
123 L4_INLINE unsigned long
124 l4_debugger_kobj_to_id_u(l4_cap_idx_t cap, l4_addr_t kobjp, l4_utcb_t *utcb) L4_NOTHROW;
125 
137 L4_INLINE long
138 l4_debugger_query_log_typeid(l4_cap_idx_t cap, const char *name,
139  unsigned idx) L4_NOTHROW;
140 
144 L4_INLINE long
145 l4_debugger_query_log_typeid_u(l4_cap_idx_t cap, const char *name,
146  unsigned idx, l4_utcb_t *utcb) L4_NOTHROW;
147 
163 L4_INLINE long
164 l4_debugger_query_log_name(l4_cap_idx_t cap, unsigned idx,
165  char *name, unsigned namelen,
166  char *shortname, unsigned shortnamelen) L4_NOTHROW;
167 
171 L4_INLINE long
172 l4_debugger_query_log_name_u(l4_cap_idx_t cap, unsigned idx,
173  char *name, unsigned namelen,
174  char *shortname, unsigned shortnamelen,
175  l4_utcb_t *utcb) L4_NOTHROW;
176 
186 L4_INLINE l4_msgtag_t
187 l4_debugger_switch_log(l4_cap_idx_t cap, const char *name,
188  int on_off) L4_NOTHROW;
189 
193 L4_INLINE l4_msgtag_t
194 l4_debugger_switch_log_u(l4_cap_idx_t cap, const char *name, int on_off,
195  l4_utcb_t *utcb) L4_NOTHROW;
196 
197 enum
198 {
199  L4_DEBUGGER_NAME_SET_OP = 0UL,
200  L4_DEBUGGER_GLOBAL_ID_OP = 1UL,
201  L4_DEBUGGER_KOBJ_TO_ID_OP = 2UL,
202  L4_DEBUGGER_QUERY_LOG_TYPEID_OP = 3UL,
203  L4_DEBUGGER_SWITCH_LOG_OP = 4UL,
204  L4_DEBUGGER_NAME_GET_OP = 5UL,
205  L4_DEBUGGER_QUERY_LOG_NAME_OP = 6UL,
206 };
207 
208 enum
209 {
210  L4_DEBUGGER_SWITCH_LOG_ON = 1,
211  L4_DEBUGGER_SWITCH_LOG_OFF = 0,
212 };
213 
214 /* IMPLEMENTATION -----------------------------------------------------------*/
215 
216 #include <l4/sys/kernel_object.h>
217 
230 L4_INLINE unsigned
231 __strcpy_maxlen(char *dst, char const *src, unsigned maxlen)
232 {
233  unsigned i;
234  if (!maxlen)
235  return 0;
236 
237  for (i = 0; i < maxlen - 1 && src[i]; ++i)
238  dst[i] = src[i];
239  dst[i] = '\0';
240 
241  return i + 1;
242 }
243 
244 L4_INLINE l4_msgtag_t
245 l4_debugger_set_object_name_u(l4_cap_idx_t cap,
246  const char *name, l4_utcb_t *utcb) L4_NOTHROW
247 {
248  unsigned i;
249  l4_utcb_mr_u(utcb)->mr[0] = L4_DEBUGGER_NAME_SET_OP;
250  i = __strcpy_maxlen((char *)&l4_utcb_mr_u(utcb)->mr[1], name,
251  (L4_UTCB_GENERIC_DATA_SIZE - 2) * sizeof(l4_umword_t));
252  i = l4_bytes_to_mwords(i);
253  return l4_invoke_debugger(cap, l4_msgtag(0, 1 + i, 0, 0), utcb);
254 }
255 
256 L4_INLINE unsigned long
257 l4_debugger_global_id_u(l4_cap_idx_t cap, l4_utcb_t *utcb) L4_NOTHROW
258 {
259  l4_utcb_mr_u(utcb)->mr[0] = L4_DEBUGGER_GLOBAL_ID_OP;
260  if (l4_error_u(l4_invoke_debugger(cap, l4_msgtag(0, 1, 0, 0), utcb), utcb))
261  return ~0UL;
262  return l4_utcb_mr_u(utcb)->mr[0];
263 }
264 
265 L4_INLINE unsigned long
266 l4_debugger_kobj_to_id_u(l4_cap_idx_t cap, l4_addr_t kobjp, l4_utcb_t *utcb) L4_NOTHROW
267 {
268  l4_utcb_mr_u(utcb)->mr[0] = L4_DEBUGGER_KOBJ_TO_ID_OP;
269  l4_utcb_mr_u(utcb)->mr[1] = kobjp;
270  if (l4_error_u(l4_invoke_debugger(cap, l4_msgtag(0, 2, 0, 0), utcb), utcb))
271  return ~0UL;
272  return l4_utcb_mr_u(utcb)->mr[0];
273 }
274 
275 L4_INLINE long
276 l4_debugger_query_log_typeid_u(l4_cap_idx_t cap, const char *name,
277  unsigned idx,
278  l4_utcb_t *utcb) L4_NOTHROW
279 {
280  unsigned i;
281  long e;
282  l4_utcb_mr_u(utcb)->mr[0] = L4_DEBUGGER_QUERY_LOG_TYPEID_OP;
283  l4_utcb_mr_u(utcb)->mr[1] = idx;
284  i = __strcpy_maxlen((char *)&l4_utcb_mr_u(utcb)->mr[2], name, 32);
285  i = l4_bytes_to_mwords(i);
286  e = l4_error_u(l4_invoke_debugger(cap, l4_msgtag(0, 2 + i, 0, 0), utcb), utcb);
287  if (e < 0)
288  return e;
289  return l4_utcb_mr_u(utcb)->mr[0];
290 }
291 
292 L4_INLINE long
293 l4_debugger_query_log_name_u(l4_cap_idx_t cap, unsigned idx,
294  char *name, unsigned namelen,
295  char *shortname, unsigned shortnamelen,
296  l4_utcb_t *utcb) L4_NOTHROW
297 {
298  long e;
299  char const *n;
300  l4_utcb_mr_u(utcb)->mr[0] = L4_DEBUGGER_QUERY_LOG_NAME_OP;
301  l4_utcb_mr_u(utcb)->mr[1] = idx;
302  e = l4_error_u(l4_invoke_debugger(cap, l4_msgtag(0, 2, 0, 0), utcb), utcb);
303  if (e < 0)
304  return e;
305  n = (char const *)&l4_utcb_mr_u(utcb)->mr[0];
306  __strcpy_maxlen(name, n, namelen);
307  __strcpy_maxlen(shortname, n + __builtin_strlen(n) + 1, shortnamelen);
308  return 0;
309 }
310 
311 
312 L4_INLINE l4_msgtag_t
313 l4_debugger_switch_log_u(l4_cap_idx_t cap, const char *name, int on_off,
314  l4_utcb_t *utcb) L4_NOTHROW
315 {
316  unsigned i;
317  l4_utcb_mr_u(utcb)->mr[0] = L4_DEBUGGER_SWITCH_LOG_OP;
318  l4_utcb_mr_u(utcb)->mr[1] = on_off;
319  i = __strcpy_maxlen((char *)&l4_utcb_mr_u(utcb)->mr[2], name, 32);
320  i = l4_bytes_to_mwords(i);
321  return l4_invoke_debugger(cap, l4_msgtag(0, 2 + i, 0, 0), utcb);
322 }
323 
324 L4_INLINE l4_msgtag_t
325 l4_debugger_get_object_name_u(l4_cap_idx_t cap, unsigned id,
326  char *name, unsigned size,
327  l4_utcb_t *utcb) L4_NOTHROW
328 {
329  l4_msgtag_t t;
330  l4_utcb_mr_u(utcb)->mr[0] = L4_DEBUGGER_NAME_GET_OP;
331  l4_utcb_mr_u(utcb)->mr[1] = id;
332  t = l4_invoke_debugger(cap, l4_msgtag(0, 2, 0, 0), utcb);
333  __strcpy_maxlen(name, (char const *)&l4_utcb_mr_u(utcb)->mr[0], size);
334  return t;
335 }
336 
337 
338 L4_INLINE l4_msgtag_t
340  const char *name) L4_NOTHROW
341 {
342  return l4_debugger_set_object_name_u(cap, name, l4_utcb());
343 }
344 
345 L4_INLINE unsigned long
347 {
348  return l4_debugger_global_id_u(cap, l4_utcb());
349 }
350 
351 L4_INLINE unsigned long
353 {
354  return l4_debugger_kobj_to_id_u(cap, kobjp, l4_utcb());
355 }
356 
357 L4_INLINE long
359  unsigned idx) L4_NOTHROW
360 {
361  return l4_debugger_query_log_typeid_u(cap, name, idx, l4_utcb());
362 }
363 
364 L4_INLINE long
366  char *name, unsigned namelen,
367  char *shortname, unsigned shortnamelen) L4_NOTHROW
368 {
369  return l4_debugger_query_log_name_u(cap, idx, name, namelen,
370  shortname, shortnamelen, l4_utcb());
371 }
372 
373 L4_INLINE l4_msgtag_t
374 l4_debugger_switch_log(l4_cap_idx_t cap, const char *name,
375  int on_off) L4_NOTHROW
376 {
377  return l4_debugger_switch_log_u(cap, name, on_off, l4_utcb());
378 }
379 
380 L4_INLINE l4_msgtag_t
382  char *name, unsigned size) L4_NOTHROW
383 {
384  return l4_debugger_get_object_name_u(cap, id, name, size, l4_utcb());
385 }
L4 compiler related defines.
#define L4_NOTHROW
Mark a function declaration and definition as never throwing an exception.
Definition: compiler.h:186
l4_msgtag_t l4_debugger_get_object_name(l4_cap_idx_t cap, unsigned id, char *name, unsigned size) L4_NOTHROW
Get name of the kernel object with Id id.
Definition: debugger.h:381
long l4_debugger_query_log_typeid(l4_cap_idx_t cap, const char *name, unsigned idx) L4_NOTHROW
Query the log-id for a log type.
Definition: debugger.h:358
long l4_debugger_query_log_name(l4_cap_idx_t cap, unsigned idx, char *name, unsigned namelen, char *shortname, unsigned shortnamelen) L4_NOTHROW
Query the name of a log type given the ID.
Definition: debugger.h:365
unsigned __strcpy_maxlen(char *dst, char const *src, unsigned maxlen)
Copy a number of characters from the C string src to the C string dst.
Definition: debugger.h:231
l4_msgtag_t l4_debugger_switch_log(l4_cap_idx_t cap, const char *name, int on_off) L4_NOTHROW
Set or unset log.
Definition: debugger.h:374
unsigned long l4_umword_t
Unsigned machine word.
Definition: l4int.h:51
unsigned long l4_addr_t
Address type.
Definition: l4int.h:45
unsigned long l4_cap_idx_t
L4 Capability selector Type.
Definition: types.h:342
unsigned long l4_debugger_kobj_to_id(l4_cap_idx_t cap, l4_addr_t kobjp) L4_NOTHROW
Get the globally unique ID of the object behind the kobject pointer.
Definition: debugger.h:352
l4_msgtag_t l4_debugger_set_object_name(l4_cap_idx_t cap, const char *name) L4_NOTHROW
Set the name of a kernel object.
Definition: debugger.h:339
unsigned long l4_debugger_global_id(l4_cap_idx_t cap) L4_NOTHROW
Get the globally unique ID of the object behind a capability.
Definition: debugger.h:346
unsigned l4_bytes_to_mwords(unsigned size) L4_NOTHROW
Determine how many machine words (l4_umword_t) are required to store a buffer of 'size' bytes.
Definition: consts.h:412
l4_msgtag_t l4_msgtag(long label, unsigned words, unsigned items, unsigned flags) L4_NOTHROW
Create a message tag from the specified values.
Definition: types.h:408
@ L4_UTCB_GENERIC_DATA_SIZE
Total number of message register (MRs) available.
Definition: utcb.h:47
struct l4_utcb_t l4_utcb_t
Opaque type for the UTCB.
Definition: utcb.h:67
l4_utcb_t * l4_utcb(void) L4_NOTHROW L4_PURE
Get the UTCB address.
Definition: utcb.h:340
Kernel object system calls.
Message tag data structure.
Definition: types.h:160
l4_umword_t mr[L4_UTCB_GENERIC_DATA_SIZE]
Message registers.
Definition: utcb.h:80