[BusyBox] insmod -m option
Goddeeris Frederic
Frederic.Goddeeris at siemens.atea.be
Tue Apr 16 11:03:03 UTC 2002
Hi Matthias,
I also have a -g option that prints a format that can be used in
add-symbol-file, but of course this is not standard...
Fred
--- insmod.c@@/main/1 Tue Nov 20 00:34:17 2001
+++ insmod.c Tue Apr 16 17:27:35 2002
@@ -625,7 +625,8 @@
static int flag_autoclean = 0;
static int flag_verbose = 0;
static int flag_export = 1;
-
+static int flag_map = 0;
+static int flag_map_gdb_output = 0;
/*======================================================================*/
@@ -713,6 +714,123 @@
/*======================================================================*/
+#ifdef BB_INSMOD_MAP
+
+static void print_gdb_sections(struct obj_file *f)
+{
+ struct obj_section *sec;
+ for (sec = f->load_order; sec; sec = sec->load_next) {
+ if (strcmp(sec->name, ".text") == 0) {
+ printf("0x%08lx ", (long)sec->header.sh_addr);
+ break;
+ }
+ }
+ for (sec = f->load_order; sec; sec = sec->load_next) {
+ if (strcmp(sec->name, ".text") != 0)
+ printf("-s %s 0x%08lx ", sec->name,
(long)sec->header.sh_addr);
+ }
+ printf("\n");
+}
+
+static void print_load_map(struct obj_file *f)
+{
+ struct obj_symbol *sym;
+ struct obj_symbol **all, **p;
+ struct obj_section *sec;
+ int load_map_cmp(const void *a, const void *b) {
+ struct obj_symbol **as = (struct obj_symbol **) a;
+ struct obj_symbol **bs = (struct obj_symbol **) b;
+ unsigned long aa = obj_symbol_final_value(f, *as);
+ unsigned long ba = obj_symbol_final_value(f, *bs);
+ return aa < ba ? -1 : aa > ba ? 1 : 0;
+ }
+ int i, nsyms, *loaded;
+
+ /* Report on the section layout. */
+
+ printf("Sections: Size %-*s Align\n",
+ (int) (2 * sizeof(void *)), "Address");
+
+ for (sec = f->load_order; sec; sec = sec->load_next) {
+ int a;
+ unsigned long tmp;
+
+ for (a = -1, tmp = sec->header.sh_addralign; tmp; ++a)
+ tmp >>= 1;
+ if (a == -1)
+ a = 0;
+
+ printf("%-16s%08lx %0*lx 2**%d\n",
+ sec->name,
+ (long)sec->header.sh_size,
+ (int) (2 * sizeof(void *)),
+ (long)sec->header.sh_addr,
+ a);
+ }
+
+ /* Quick reference which section indicies are loaded. */
+
+ loaded = alloca(sizeof(int) * (i = f->header.e_shnum));
+ while (--i >= 0)
+ loaded[i] = (f->sections[i]->header.sh_flags & SHF_ALLOC) !=
0;
+
+ /* Collect the symbols we'll be listing. */
+
+ for (nsyms = i = 0; i < HASH_BUCKETS; ++i)
+ for (sym = f->symtab[i]; sym; sym = sym->next)
+ if (sym->secidx <= SHN_HIRESERVE
+ && (sym->secidx >= SHN_LORESERVE ||
loaded[sym->secidx]))
+ ++nsyms;
+
+ all = alloca(nsyms * sizeof(struct obj_symbol *));
+
+ for (i = 0, p = all; i < HASH_BUCKETS; ++i)
+ for (sym = f->symtab[i]; sym; sym = sym->next)
+ if (sym->secidx <= SHN_HIRESERVE
+ && (sym->secidx >= SHN_LORESERVE ||
loaded[sym->secidx]))
+ *p++ = sym;
+
+ /* Sort them by final value. */
+ qsort(all, nsyms, sizeof(struct obj_file *), load_map_cmp);
+
+ /* And list them. */
+ printf("\nSymbols:");
+ for (p = all; p < all + nsyms; ++p) {
+ char type = '?';
+ unsigned long value;
+
+ sym = *p;
+ if (sym->secidx == SHN_ABS) {
+ type = 'A';
+ value = sym->value;
+ } else if (sym->secidx == SHN_UNDEF) {
+ type = 'U';
+ value = 0;
+ } else {
+ struct obj_section *sec = f->sections[sym->secidx];
+
+ if (sec->header.sh_type == SHT_NOBITS)
+ type = 'B';
+ else if (sec->header.sh_flags & SHF_ALLOC) {
+ if (sec->header.sh_flags & SHF_EXECINSTR)
+ type = 'T';
+ else if (sec->header.sh_flags & SHF_WRITE)
+ type = 'D';
+ else
+ type = 'R';
+ }
+ value = sym->value + sec->header.sh_addr;
+ }
+
+ if (ELFW(ST_BIND) (sym->info) == STB_LOCAL)
+ type = tolower(type);
+
+ printf("%0*lx %c %s\n", (int) (2 * sizeof(void *)), value,
+ type, sym->name);
+ }
+}
+#endif // BB_INSMOD_MAP
+
static int check_module_name_match(const char *filename, struct stat
*statbuf,
void *userdata)
{
@@ -2009,6 +2127,15 @@
image = xmalloc(m_size);
obj_create_image(f, image);
+
+#ifdef BB_INSMOD_MAP
+ if (flag_map_gdb_output)
+ print_gdb_sections(f);
+ if (flag_map)
+ print_load_map(f);
+#endif
+ // *****
+
/* image holds the complete relocated module, accounting correctly
for
mod_use_count. However the old module kernel support assume that
it is receiving something which does not contain mod_use_count.
*/
@@ -2581,6 +2708,15 @@
image = xmalloc(m_size);
obj_create_image(f, image);
+
+#ifdef BB_INSMOD_MAP
+ if (flag_map_gdb_output)
+ print_gdb_sections(f);
+ if (flag_map)
+ print_load_map(f);
+#endif
+ // *****
+
ret = new_sys_init_module(m_name, (struct new_module *) image);
if (ret)
perror_msg("init_module: %s", m_name);
@@ -3226,7 +3362,7 @@
#endif
/* Parse any options */
- while ((opt = getopt(argc, argv, "fkvxLo:")) > 0) {
+ while ((opt = getopt(argc, argv, "fkvxLo:mg")) > 0) {
switch (opt) {
case 'f': /* force loading */
flag_force_load = 1;
@@ -3243,6 +3379,12 @@
case 'o': /* name the output
module */
strncpy(m_name, optarg, FILENAME_MAX);
break;
+ case 'm':
+ flag_map = 1;
+ break;
+ case 'g':
+ flag_map_gdb_output = 1;
+ break;
case 'L': /* Stub warning */
/* This is needed for compatibility with
modprobe.
* In theory, this does locking, but we
don't do
@@ -3479,3 +3621,6 @@
fclose(fp);
return(exit_status);
}
+
+
+
-----Original Message-----
From: Matthias Fuchs [mailto:matthias.fuchs at esd-electronics.com]
Sent: vrijdag 12 april 2002 9:38
To: Goddeeris Frederic
Subject: Re: [BusyBox] insmod -m option
Hello Frederic,
Goddeeris Frederic wrote:
> Hi,
>
> I did not do anything with it yet.
>
> I will make a patch from it if you like, but it will only be tomorrow or
> even after the weekend.
Keep your time. I am not in a hurry.
I could also send you the complete file but I have a
> problem with global variables that are not correctly initialized and it
> seems it is solved in more recent versions. Do you have any experience
with
> this issue?
Not really.
Matthias
>
> Fred
>
> -----Original Message-----
> From: Matthias Fuchs [mailto:matthias.fuchs at esd-electronics.com]
> Sent: donderdag 11 april 2002 17:07
> To: Goddeeris Frederic
> Subject: Re: [BusyBox] insmod -m option
>
>
> Hi Frederic,
>
> i read your posting in the busybox list.
>
> Do you know what happened with your "-m" option for insmod ?
> Did you post a patch or is it still included ?
>
> I am very interessted in the "-m" option, since it is useful for
debugging.
>
> Can you send me a patch ?
>
> Thanks
> Matthias
>
> Goddeeris Frederic wrote:
>
>
>>Hi,
>>
>>I added the -m option to insmod. Do I make a patch, or is there a reason
>>this was not added to busybox before?
>>
>>Would it be a good idea to add an option that prints the section addresses
>>in the format that gdb expects in the add-symbol-file command? I have seen
>>
> a
>
>>script that transforms the normal map output but it uses awk.
>>
>>Frederic
>>_______________________________________________
>>busybox mailing list
>>busybox at busybox.net
>>http://busybox.net/mailman/listinfo/busybox
>>
>>
>>
>>
>>
>
>
--
-------------------------------------------------------------------------
_/_/_/_/ Matthias Fuchs
_/_/_/_/ Dipl.-Ing.
_/_/_/_/ matthias.fuchs at esd-electronics.com
_/_/_/ _/_/_/_/_/_/_/ esd electronic system design gmbh
_/ _/ _/ _/ Vahrenwalder Str. 207
_/ _/ _/_/_/ _/ _/ D-30165 Hannover
_/ _/ _/ _/ Phone: +49-511-37298-0
_/_/_/_/_/_/_/ _/_/_/ Fax: +49-511-37298-68
-------------------------------------------------------------------------
More information about the busybox
mailing list