4 * \brief Debugger related definitions.
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)
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.
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.
26 #include <l4/sys/compiler.h>
27 #include <l4/sys/utcb.h>
28 #include <l4/sys/ipc.h>
31 * \defgroup l4_debugger_api Kernel Debugger
32 * \ingroup api_calls_fiasco
33 * \brief Kernel debugger related functionality.
34 * \attention This API is subject to change!
36 * This is a debugging facility, any call to any function might be invalid.
37 * Do not rely on it in any real code.
39 * \includefile{l4/sys/debugger.h}
44 * Set the name of a kernel object.
45 * \ingroup l4_debugger_api
47 * \param cap Capability which refers to the kernel object.
48 * \param name Name of the kernel object that is e.g. displayed in the
51 * This is a debugging facility, the call might be invalid.
54 l4_debugger_set_object_name(l4_cap_idx_t cap, const char *name) L4_NOTHROW;
60 l4_debugger_set_object_name_u(l4_cap_idx_t cap, const char *name, l4_utcb_t *utcb) L4_NOTHROW;
63 * Get name of the kernel object with Id `id`.
65 * \param cap Capability of the debugger object.
66 * \param id Global id of the object whose name is asked.
67 * \param[out] name Buffer to copy the name into. The buffer must be
68 * allocated by the caller.
69 * \param size Length of the `name` buffer.
71 * \return Syscall return tag
74 l4_debugger_get_object_name(l4_cap_idx_t cap, unsigned id,
75 char *name, unsigned size) L4_NOTHROW;
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;
86 * Get the globally unique ID of the object behind a capability.
87 * \ingroup l4_debugger_api
89 * \param cap Capability
91 * \retval ~0UL Capability is not valid.
92 * \retval >=0 Global debugger id.
94 * This is a debugging facility, the call might be invalid.
96 L4_INLINE unsigned long
97 l4_debugger_global_id(l4_cap_idx_t cap) L4_NOTHROW;
102 L4_INLINE unsigned long
103 l4_debugger_global_id_u(l4_cap_idx_t cap, l4_utcb_t *utcb) L4_NOTHROW;
106 * Get the globally unique ID of the object behind the kobject pointer.
107 * \ingroup l4_debugger_api
109 * \param cap Capability
110 * \param kobjp Kobject pointer
112 * \retval ~0UL The capability or the kobject pointer are invalid.
113 * \retval >=0 The globally unique id.
115 * This is a debugging facility, the call might be invalid.
117 L4_INLINE unsigned long
118 l4_debugger_kobj_to_id(l4_cap_idx_t cap, l4_addr_t kobjp) L4_NOTHROW;
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;
127 * \brief Query the log-id for a log type
129 * \param cap Debugger capability
130 * \param name Name to query for.
131 * \param idx Idx to start searching, start with 0
133 * \return positive ID, or negative error code
135 * This is a debugging facility, the call might be invalid.
138 l4_debugger_query_log_typeid(l4_cap_idx_t cap, const char *name,
139 unsigned idx) L4_NOTHROW;
145 l4_debugger_query_log_typeid_u(l4_cap_idx_t cap, const char *name,
146 unsigned idx, l4_utcb_t *utcb) L4_NOTHROW;
149 * \brief Query the name of a log type given the ID
151 * \param cap Debugger capability.
152 * \param idx ID to query.
153 * \param name Buffer to copy name to.
154 * \param namelen Buffer length of name.
155 * \param shortname Buffer to copy `shortname` to.
156 * \param shortnamelen Buffer length of `shortname`.
161 * This is a debugging facility, the call might be invalid.
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;
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;
180 * \param cap Debugger object.
181 * \param name Name of the log type.
182 * \param on_off 1: turn log on, 0: turn log off
184 * \return Syscall return tag
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;
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;
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,
210 L4_DEBUGGER_SWITCH_LOG_ON = 1,
211 L4_DEBUGGER_SWITCH_LOG_OFF = 0,
214 /* IMPLEMENTATION -----------------------------------------------------------*/
216 #include <l4/sys/kernel_object.h>
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
223 char *s = (char *)&l4_utcb_mr_u(utcb)->mr[1];
224 l4_utcb_mr_u(utcb)->mr[0] = L4_DEBUGGER_NAME_SET_OP;
226 *name && i < (L4_UTCB_GENERIC_DATA_SIZE - 2) * sizeof(l4_umword_t) - 1;
230 i = (i + sizeof(l4_umword_t) - 1) / sizeof(l4_umword_t);
231 return l4_invoke_debugger(cap, l4_msgtag(0, i, 0, 0), utcb);
234 L4_INLINE unsigned long
235 l4_debugger_global_id_u(l4_cap_idx_t cap, l4_utcb_t *utcb) L4_NOTHROW
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))
240 return l4_utcb_mr_u(utcb)->mr[0];
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
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))
250 return l4_utcb_mr_u(utcb)->mr[0];
254 l4_debugger_query_log_typeid_u(l4_cap_idx_t cap, const char *name,
256 l4_utcb_t *utcb) L4_NOTHROW
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);
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);
269 return l4_utcb_mr_u(utcb)->mr[0];
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
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);
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;
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
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);
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);
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
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);
323 L4_INLINE l4_msgtag_t
324 l4_debugger_set_object_name(unsigned long cap,
325 const char *name) L4_NOTHROW
327 return l4_debugger_set_object_name_u(cap, name, l4_utcb());
330 L4_INLINE unsigned long
331 l4_debugger_global_id(l4_cap_idx_t cap) L4_NOTHROW
333 return l4_debugger_global_id_u(cap, l4_utcb());
336 L4_INLINE unsigned long
337 l4_debugger_kobj_to_id(l4_cap_idx_t cap, l4_addr_t kobjp) L4_NOTHROW
339 return l4_debugger_kobj_to_id_u(cap, kobjp, l4_utcb());
343 l4_debugger_query_log_typeid(l4_cap_idx_t cap, const char *name,
344 unsigned idx) L4_NOTHROW
346 return l4_debugger_query_log_typeid_u(cap, name, idx, l4_utcb());
350 l4_debugger_query_log_name(l4_cap_idx_t cap, unsigned idx,
351 char *name, unsigned namelen,
352 char *shortname, unsigned shortnamelen) L4_NOTHROW
354 return l4_debugger_query_log_name_u(cap, idx, name, namelen,
355 shortname, shortnamelen, l4_utcb());
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
362 return l4_debugger_switch_log_u(cap, name, on_off, l4_utcb());
365 L4_INLINE l4_msgtag_t
366 l4_debugger_get_object_name(l4_cap_idx_t cap, unsigned id,
367 char *name, unsigned size) L4_NOTHROW
369 return l4_debugger_get_object_name_u(cap, id, name, size, l4_utcb());