aboutsummaryrefslogtreecommitdiff
path: root/ld/ldlang.c
diff options
context:
space:
mode:
authorTristan Gingold <gingold@adacore.com>2015-06-05 15:09:31 +0200
committerTristan Gingold <gingold@adacore.com>2015-06-12 11:24:36 +0200
commit3604cb1f8ca4a926039a9540d03bb224d84af3e1 (patch)
tree962d40b3cb6bd43d06960653b70af6d73a207e66 /ld/ldlang.c
parentdb7858e227f3951c665410314fca62c77349ac24 (diff)
downloadgdb-3604cb1f8ca4a926039a9540d03bb224d84af3e1.zip
gdb-3604cb1f8ca4a926039a9540d03bb224d84af3e1.tar.gz
gdb-3604cb1f8ca4a926039a9540d03bb224d84af3e1.tar.bz2
Add new ld option: --print-memory-usage
ld/ * NEWS: Mention new option. * lexsup.c (parse_args): Handle --print-memory-usage. (ld_options): Add --print-memory-usage. * ldmain.c (main): Call lang_print_memory_usage. * ldlex.h (enum option_values): Add OPTION_PRINT_MEMORY_USAGE. * ldlang.h: Add prototype of lang_print_memory_usage. * ldlang.c (lang_print_memory_size, lang_print_memory_usage): New functions. * ld.texinfo (Options): Document --print-memory-usage. * ld.h (args_type): Add print_memory_usage field. ld/testsuite/ * ld-scripts/print-memory-usage-1.t, * ld-scripts/print-memory-usage-1.s, * ld-scripts/print-memory-usage-1.l, * ld-scripts/print-memory-usage-2.t, * ld-scripts/print-memory-usage-2.l, * ld-scripts/print-memory-usage-3.s, * ld-scripts/print-memory-usage-3.t, * ld-scripts/print-memory-usage-3.l, * ld-scripts/print-memory-usage.t: New tests. * ld-scripts/print-memory-usage.exp: Run them.
Diffstat (limited to 'ld/ldlang.c')
-rw-r--r--ld/ldlang.c38
1 files changed, 38 insertions, 0 deletions
diff --git a/ld/ldlang.c b/ld/ldlang.c
index c96c21f..b816d69 100644
--- a/ld/ldlang.c
+++ b/ld/ldlang.c
@@ -8133,3 +8133,41 @@ lang_ld_feature (char *str)
p = q;
}
}
+
+/* Pretty print memory amount. */
+
+static void
+lang_print_memory_size (bfd_vma sz)
+{
+ if ((sz & 0x3fffffff) == 0)
+ printf ("%10" BFD_VMA_FMT "u GB", sz >> 30);
+ else if ((sz & 0xfffff) == 0)
+ printf ("%10" BFD_VMA_FMT "u MB", sz >> 20);
+ else if ((sz & 0x3ff) == 0)
+ printf ("%10" BFD_VMA_FMT "u KB", sz >> 10);
+ else
+ printf (" %10" BFD_VMA_FMT "u B", sz);
+}
+
+/* Implement --print-memory-usage: disply per region memory usage. */
+
+void
+lang_print_memory_usage (void)
+{
+ lang_memory_region_type *r;
+
+ printf ("Memory region Used Size Region Size %%age Used\n");
+ for (r = lang_memory_region_list; r->next != NULL; r = r->next)
+ {
+ bfd_vma used_length = r->current - r->origin;
+ double percent;
+
+ printf ("%16s: ",r->name_list.name);
+ lang_print_memory_size (used_length);
+ lang_print_memory_size ((bfd_vma) r->length);
+
+ percent = used_length * 100.0 / r->length;
+
+ printf (" %6.2f%%\n", percent);
+ }
+}