1 //-----------------------------------------------------------------------
5 #include "jdb_kobject.h"
10 class Jdb_kobject_name : public Jdb_kobject_extension
13 static char const *const static_type;
14 virtual char const *type() const { return static_type; }
16 ~Jdb_kobject_name() {}
18 void *operator new (size_t) throw();
19 void operator delete (void *);
25 static Jdb_kobject_name *_names;
28 //-----------------------------------------------------------------------
35 #include "kmem_alloc.h"
40 #include "static_init.h"
46 Name_buffer_size = 8192,
47 Name_entries = Name_buffer_size / sizeof(Jdb_kobject_name),
51 char const *const Jdb_kobject_name::static_type = "Jdb_kobject_names";
52 Jdb_kobject_name *Jdb_kobject_name::_names;
57 Jdb_kobject_name::max_len()
58 { return sizeof(_name); }
62 Jdb_kobject_name::name(char const *name)
64 strncpy(_name, name, sizeof(_name));
68 Jdb_kobject_name::Jdb_kobject_name()
71 static Spin_lock<> allocator_lock;
75 Jdb_kobject_name::operator new (size_t) throw()
77 Jdb_kobject_name *n = _names;
80 void **o = reinterpret_cast<void**>(n);
83 auto g = lock_guard(allocator_lock);
93 if ((n - _names) >= Name_entries)
100 Jdb_kobject_name::operator delete (void *p)
102 auto g = lock_guard(allocator_lock);
103 void **o = reinterpret_cast<void**>(p);
109 Jdb_kobject_name::clear_name()
111 for (unsigned i = 0; i < max_len(); ++i)
117 Jdb_kobject_name::name() const
122 Jdb_kobject_name::name()
125 class Jdb_name_hdl : public Jdb_kobject_handler
128 Jdb_name_hdl() : Jdb_kobject_handler(0) {}
129 virtual bool show_kobject(Kobject_common *, int) { return true; }
130 virtual ~Jdb_name_hdl() {}
135 Jdb_name_hdl::show_kobject_short(char *buf, int max, Kobject_common *o)
138 = Jdb_kobject_extension::find_extension<Jdb_kobject_name>(o);
141 return snprintf(buf, max, " {%-*.*s}", ex->max_len(), ex->max_len(), ex->name());
148 Jdb_name_hdl::invoke(Kobject_common *o, Syscall_frame *f, Utcb *utcb)
150 switch (utcb->values[0])
154 Jdb_kobject_name *ne = new Jdb_kobject_name();
157 f->tag(Kobject_iface::commit_result(-L4_err::ENomem));
161 char const *name = reinterpret_cast<char const*>(&utcb->values[1]);
163 strncpy(ne->name(), name, ne->max_len());
164 o->dbg_info()->_jdb_data.add(ne);
165 f->tag(Kobject_iface::commit_result(0));
170 Kobject_dbg::Iterator o = Kobject_dbg::id_to_obj(utcb->values[1]);
171 if (o == Kobject_dbg::end())
173 f->tag(Kobject_iface::commit_result(-L4_err::ENoent));
176 Jdb_kobject_name *n = Jdb_kobject_extension::find_extension<Jdb_kobject_name>(Kobject::from_dbg(o));
179 f->tag(Kobject_iface::commit_result(-L4_err::ENoent));
183 unsigned l = min<unsigned>(n->max_len(), sizeof(utcb->values));
184 char *dst = reinterpret_cast<char *>(utcb->values);
185 strncpy(dst, n->name(), l);
188 f->tag(Kobject_iface::commit_result(0));
195 PUBLIC static FIASCO_INIT
197 Jdb_kobject_name::init()
199 _names = (Jdb_kobject_name*)Kmem_alloc::allocator()->unaligned_alloc(Name_buffer_size);
201 panic("No memory for thread names");
203 for (int i=0; i<Name_entries; i++)
204 *reinterpret_cast<unsigned long*>(_names + i) = 0;
206 static Jdb_name_hdl hdl;
207 Jdb_kobject::module()->register_handler(&hdl);
211 STATIC_INITIALIZE(Jdb_kobject_name);