summaryrefslogtreecommitdiff
path: root/rts/IPE.c
diff options
context:
space:
mode:
authorMatthew Pickering <matthewtpickering@gmail.com>2020-11-18 11:36:07 +0000
committerMatthew Pickering <matthewtpickering@gmail.com>2021-03-03 19:09:34 +0000
commit4b297979d25740d31241a9000e36068db112545a (patch)
treee2e40fa7922fb4a91125c73fcbae04e7a6a66f73 /rts/IPE.c
parent8402ea951b31e01a925ca691747d1757eaf31fcc (diff)
downloadhaskell-4b297979d25740d31241a9000e36068db112545a.tar.gz
Add -finfo-table-map which maps info tables to source positions
This new flag embeds a lookup table from the address of an info table to information about that info table. The main interface for consulting the map is the `lookupIPE` C function > InfoProvEnt * lookupIPE(StgInfoTable *info) The `InfoProvEnt` has the following structure: > typedef struct InfoProv_{ > char * table_name; > char * closure_desc; > char * ty_desc; > char * label; > char * module; > char * srcloc; > } InfoProv; > > typedef struct InfoProvEnt_ { > StgInfoTable * info; > InfoProv prov; > struct InfoProvEnt_ *link; > } InfoProvEnt; The source positions are approximated in a similar way to the source positions for DWARF debugging information. They are only approximate but in our experience provide a good enough hint about where the problem might be. It is therefore recommended to use this flag in conjunction with `-g<n>` for more accurate locations. The lookup table is also emitted into the eventlog when it is available as it is intended to be used with the `-hi` profiling mode. Using this flag will significantly increase the size of the resulting object file but only by a factor of 2-3x in our experience.
Diffstat (limited to 'rts/IPE.c')
-rw-r--r--rts/IPE.c81
1 files changed, 81 insertions, 0 deletions
diff --git a/rts/IPE.c b/rts/IPE.c
new file mode 100644
index 0000000000..d881682e7d
--- /dev/null
+++ b/rts/IPE.c
@@ -0,0 +1,81 @@
+/* -----------------------------------------------------------------------------
+ *
+ * (c) The GHC Team, 1998-2000
+ *
+ * Support for mapping info table pointers to source locations
+ *
+ * ---------------------------------------------------------------------------*/
+
+
+#include "PosixSource.h"
+#include "Rts.h"
+
+#include "RtsUtils.h"
+#include "Profiling.h"
+#include "Arena.h"
+#include "IPE.h"
+#include "Printer.h"
+#include "Capability.h"
+
+#include <fs_rts.h>
+#include <string.h>
+
+
+#if defined(TRACING)
+#include "Trace.h"
+#endif
+
+InfoProvEnt *IPE_LIST = NULL;
+
+void dumpIPEToEventLog(void)
+{
+#if defined(TRACING)
+ InfoProvEnt *ip, *next;
+ for (ip = IPE_LIST; ip != NULL; ip = next) {
+ next = ip->link;
+ traceIPE(ip->info, ip->prov.table_name, ip->prov.closure_desc, ip->prov.ty_desc
+ , ip->prov.label, ip->prov.module, ip->prov.srcloc);
+ }
+#endif
+ return;
+}
+
+
+/* -----------------------------------------------------------------------------
+ Registering IPEs
+
+ Registering a IPE consists of linking it onto the list of registered IPEs
+
+ IPEs are registered at startup by a C constructor function
+ generated by the compiler (ProfInit.hs) in the _stub.c file for each module.
+ -------------------------------------------------------------------------- */
+
+static void
+registerInfoProvEnt(InfoProvEnt *ipe)
+{
+ ASSERT(ipe->link == NULL);
+ ipe->link = IPE_LIST;
+ IPE_LIST = ipe;
+}
+
+void registerInfoProvList(InfoProvEnt **ent_list)
+{
+ for (InfoProvEnt **i = ent_list; *i != NULL; i++) {
+ registerInfoProvEnt(*i);
+ }
+}
+
+
+// MP: TODO: This should not be a linear search, need to improve
+// the IPE_LIST structure
+InfoProvEnt * lookupIPE(StgInfoTable *info)
+{
+ InfoProvEnt *ip, *next;
+ for (ip = IPE_LIST; ip != NULL; ip = next) {
+ if (ip->info == info) {
+ return ip;
+ }
+ next = ip->link;
+ }
+ return NULL;
+}