I try to print Linux linked list in user friendly way in Trace32.
1. Is there already any known method available?
If not then let me show an example with modules list.
I have global variable
static struct list_head modules;
where
struct list_head {
struct list_head *next, *prev;
};
So, in T32 I just see list of next and prev pointers when doing v.v modules
, no useful info in fact. However, every node of modules list is a part of a container type. In this case struct module
struct module {
...
struct list_head list;
...
}
Normally, to extract container pointer Linux uses container_of macro.
/**
* container_of - cast a member of a structure out to the containing structure
* @ptr: the pointer to the member.
* @type: the type of the container struct this is embedded in.
* @member: the name of the member within the struct.
*
*/
#define container_of(ptr, type, member) ({ \
const typeof( ((type *)0)->member ) *__mptr = (ptr); \
(type *)( (char *)__mptr - offsetof(type,member) );})
In our example we know the pointer to struct list_head
which is a list
member in struct module
then we should call container_of(modules->next, struct module, list)
to get a pointer to the container.
To be able to archive this in T32 I need to calculate offset of the list
member in container type.
Anyone knows how to achieve this?