L4Re - L4 Runtime Environment
debugger.h
Go to the documentation of this file.
1 #pragma once
2 
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 int
138 l4_debugger_query_log_typeid(l4_cap_idx_t cap, const char *name,
139  unsigned idx) L4_NOTHROW;
140 
144 L4_INLINE int
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 int
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 int
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 
218 L4_INLINE l4_msgtag_t
219 l4_debugger_set_object_name_u(unsigned long cap,
220  const char *name, l4_utcb_t *utcb) L4_NOTHROW
221 {
222  unsigned int i;
223  char *s = (char *)&l4_utcb_mr_u(utcb)->mr[1];
224  l4_utcb_mr_u(utcb)->mr[0] = L4_DEBUGGER_NAME_SET_OP;
225  for (i = 0;
226  *name && i < (L4_UTCB_GENERIC_DATA_SIZE - 2) * sizeof(l4_umword_t) - 1;
227  ++i, ++name, ++s)
228  *s = *name;
229  *s = 0;
230  i = (i + sizeof(l4_umword_t) - 1) / sizeof(l4_umword_t);
231  return l4_invoke_debugger(cap, l4_msgtag(0, i + 1, 0, 0), utcb);
232 }
233 
234 L4_INLINE unsigned long
235 l4_debugger_global_id_u(l4_cap_idx_t cap, l4_utcb_t *utcb) L4_NOTHROW
236 {
237  l4_utcb_mr_u(utcb)->mr[0] = L4_DEBUGGER_GLOBAL_ID_OP;
238  if (l4_error_u(l4_invoke_debugger(cap, l4_msgtag(0, 1, 0, 0), utcb), utcb))
239  return ~0UL;
240  return l4_utcb_mr_u(utcb)->mr[0];
241 }
242 
243 L4_INLINE unsigned long
244 l4_debugger_kobj_to_id_u(l4_cap_idx_t cap, l4_addr_t kobjp, l4_utcb_t *utcb) L4_NOTHROW
245 {
246  l4_utcb_mr_u(utcb)->mr[0] = L4_DEBUGGER_KOBJ_TO_ID_OP;
247  l4_utcb_mr_u(utcb)->mr[1] = kobjp;
248  if (l4_error_u(l4_invoke_debugger(cap, l4_msgtag(0, 2, 0, 0), utcb), utcb))
249  return ~0UL;
250  return l4_utcb_mr_u(utcb)->mr[0];
251 }
252 
253 L4_INLINE int
254 l4_debugger_query_log_typeid_u(l4_cap_idx_t cap, const char *name,
255  unsigned idx,
256  l4_utcb_t *utcb) L4_NOTHROW
257 {
258  unsigned l;
259  int e;
260  l4_utcb_mr_u(utcb)->mr[0] = L4_DEBUGGER_QUERY_LOG_TYPEID_OP;
261  l4_utcb_mr_u(utcb)->mr[1] = idx;
262  l = __builtin_strlen(name);
263  l = l > 31 ? 31 : l;
264  __builtin_strncpy((char *)&l4_utcb_mr_u(utcb)->mr[2], name, 31);
265  l = (l + 1 + sizeof(l4_umword_t) - 1) / sizeof(l4_umword_t);
266  e = l4_error_u(l4_invoke_debugger(cap, l4_msgtag(0, 2 + l, 0, 0), utcb), utcb);
267  if (e < 0)
268  return e;
269  return l4_utcb_mr_u(utcb)->mr[0];
270 }
271 
272 L4_INLINE int
273 l4_debugger_query_log_name_u(l4_cap_idx_t cap, unsigned idx,
274  char *name, unsigned namelen,
275  char *shortname, unsigned shortnamelen,
276  l4_utcb_t *utcb) L4_NOTHROW
277 {
278  int e;
279  char *n;
280  l4_utcb_mr_u(utcb)->mr[0] = L4_DEBUGGER_QUERY_LOG_NAME_OP;
281  l4_utcb_mr_u(utcb)->mr[1] = idx;
282  e = l4_error_u(l4_invoke_debugger(cap, l4_msgtag(0, 2, 0, 0), utcb), utcb);
283  if (e < 0)
284  return e;
285  n = (char *)&l4_utcb_mr_u(utcb)->mr[0];
286  __builtin_strncpy(name, n, namelen);
287  name[namelen - 1] = 0;
288  __builtin_strncpy(shortname, n + __builtin_strlen(n) + 1, shortnamelen);
289  shortname[shortnamelen - 1] = 0;
290  return 0;
291 }
292 
293 
294 L4_INLINE l4_msgtag_t
295 l4_debugger_switch_log_u(l4_cap_idx_t cap, const char *name, int on_off,
296  l4_utcb_t *utcb) L4_NOTHROW
297 {
298  unsigned l;
299  l4_utcb_mr_u(utcb)->mr[0] = L4_DEBUGGER_SWITCH_LOG_OP;
300  l4_utcb_mr_u(utcb)->mr[1] = on_off;
301  l = __builtin_strlen(name);
302  l = l > 31 ? 31 : l;
303  __builtin_strncpy((char *)&l4_utcb_mr_u(utcb)->mr[2], name, 31);
304  l = (l + 1 + sizeof(l4_umword_t) - 1) / sizeof(l4_umword_t);
305  return l4_invoke_debugger(cap, l4_msgtag(0, 2 + l, 0, 0), utcb);
306 }
307 
308 L4_INLINE l4_msgtag_t
309 l4_debugger_get_object_name_u(l4_cap_idx_t cap, unsigned id,
310  char *name, unsigned size,
311  l4_utcb_t *utcb) L4_NOTHROW
312 {
313  l4_msgtag_t t;
314  l4_utcb_mr_u(utcb)->mr[0] = L4_DEBUGGER_NAME_GET_OP;
315  l4_utcb_mr_u(utcb)->mr[1] = id;
316  t = l4_invoke_debugger(cap, l4_msgtag(0, 2, 0, 0), utcb);
317  __builtin_strncpy(name, (char *)&l4_utcb_mr_u(utcb)->mr[0], size);
318  name[size - 1] = 0;
319  return t;
320 }
321 
322 
323 L4_INLINE l4_msgtag_t
324 l4_debugger_set_object_name(unsigned long cap,
325  const char *name) L4_NOTHROW
326 {
327  return l4_debugger_set_object_name_u(cap, name, l4_utcb());
328 }
329 
330 L4_INLINE unsigned long
332 {
333  return l4_debugger_global_id_u(cap, l4_utcb());
334 }
335 
336 L4_INLINE unsigned long
338 {
339  return l4_debugger_kobj_to_id_u(cap, kobjp, l4_utcb());
340 }
341 
342 L4_INLINE int
344  unsigned idx) L4_NOTHROW
345 {
346  return l4_debugger_query_log_typeid_u(cap, name, idx, l4_utcb());
347 }
348 
349 L4_INLINE int
351  char *name, unsigned namelen,
352  char *shortname, unsigned shortnamelen) L4_NOTHROW
353 {
354  return l4_debugger_query_log_name_u(cap, idx, name, namelen,
355  shortname, shortnamelen, l4_utcb());
356 }
357 
358 L4_INLINE l4_msgtag_t
359 l4_debugger_switch_log(l4_cap_idx_t cap, const char *name,
360  int on_off) L4_NOTHROW
361 {
362  return l4_debugger_switch_log_u(cap, name, on_off, l4_utcb());
363 }
364 
365 L4_INLINE l4_msgtag_t
367  char *name, unsigned size) L4_NOTHROW
368 {
369  return l4_debugger_get_object_name_u(cap, id, name, size, l4_utcb());
370 }
Total number of message register (MRs) available.
Definition: utcb.h:47
int 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:350
int 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:343
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:331
l4_umword_t mr[L4_UTCB_GENERIC_DATA_SIZE]
Message registers.
Definition: utcb.h:80
unsigned long l4_cap_idx_t
L4 Capability selector Type.
Definition: types.h:342
struct l4_utcb_t l4_utcb_t
Opaque type for the UTCB.
Definition: utcb.h:67
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:366
L4 compiler related defines.
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:337
unsigned long l4_umword_t
Unsigned machine word.
Definition: l4int.h:52
l4_utcb_t * l4_utcb(void) L4_NOTHROW L4_PURE
Get the UTCB address.
Definition: utcb.h:340
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
Kernel object system calls.
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:324
Message tag data structure.
Definition: types.h:159
unsigned long l4_addr_t
Address type.
Definition: l4int.h:45
#define L4_NOTHROW
Mark a function declaration and definition as never throwing an exception.
Definition: compiler.h:185
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:359