summaryrefslogtreecommitdiff
path: root/gdb/objfiles.h
diff options
context:
space:
mode:
authorPedro Alves <pedro@codesourcery.com>2010-09-24 11:15:51 +0000
committerPedro Alves <pedro@codesourcery.com>2010-09-24 11:15:51 +0000
commit328d04710b395061e65b4c9d3e063ff4ff9d5117 (patch)
tree73dab1b6c6a080bda514d8d5d70c050e24f0eec4 /gdb/objfiles.h
parent120873b176cfac0958e0378feec2c46139890545 (diff)
downloadgdb-328d04710b395061e65b4c9d3e063ff4ff9d5117.tar.gz
* objfiles.h (ALL_OBJSECTIONS): Handle breaks in the inner loop.
Diffstat (limited to 'gdb/objfiles.h')
-rw-r--r--gdb/objfiles.h41
1 files changed, 38 insertions, 3 deletions
diff --git a/gdb/objfiles.h b/gdb/objfiles.h
index b3e2e26faac..8b47d2bbfaf 100644
--- a/gdb/objfiles.h
+++ b/gdb/objfiles.h
@@ -611,9 +611,44 @@ extern int gdb_bfd_close_or_warn (struct bfd *abfd);
#define ALL_OBJFILE_OSECTIONS(objfile, osect) \
for (osect = objfile->sections; osect < objfile->sections_end; osect++)
-#define ALL_OBJSECTIONS(objfile, osect) \
- ALL_OBJFILES (objfile) \
- ALL_OBJFILE_OSECTIONS (objfile, osect)
+/* Traverse all obj_sections in all objfiles in the current program
+ space.
+
+ Note that this detects a "break" in the inner loop, and exits
+ immediately from the outer loop as well, thus, client code doesn't
+ need to know that this is implemented with a double for. The extra
+ hair is to make sure that a "break;" stops the outer loop iterating
+ as well, and both OBJFILE and OSECT are left unmodified:
+
+ - The outer loop learns about the inner loop's end condition, and
+ stops iterating if it detects the inner loop didn't reach its
+ end. In other words, the outer loop keeps going only if the
+ inner loop reached its end cleanly [(osect) ==
+ (objfile)->sections_end].
+
+ - OSECT is initialized in the outer loop initialization
+ expressions, such as if the inner loop has reached its end, so
+ the check mentioned above succeeds the first time.
+
+ - The trick to not clearing OBJFILE on a "break;" is, in the outer
+ loop's loop expression, advance OBJFILE, but iff the inner loop
+ reached its end. If not, there was a "break;", so leave OBJFILE
+ as is; the outer loop's conditional will break immediately as
+ well (as OSECT will be different from OBJFILE->sections_end).
+*/
+
+#define ALL_OBJSECTIONS(objfile, osect) \
+ for ((objfile) = current_program_space->objfiles, \
+ (objfile) != NULL ? ((osect) = (objfile)->sections_end) : 0; \
+ (objfile) != NULL \
+ && (osect) == (objfile)->sections_end; \
+ ((osect) == (objfile)->sections_end \
+ ? ((objfile) = (objfile)->next, \
+ (objfile) != NULL ? (osect) = (objfile)->sections_end : 0) \
+ : 0)) \
+ for ((osect) = (objfile)->sections; \
+ (osect) < (objfile)->sections_end; \
+ (osect)++)
#define SECT_OFF_DATA(objfile) \
((objfile->sect_index_data == -1) \