of variables any more (the file target is handling them and they
never get to the process target). So when you push a file target,
it goes into the file stratum, which is always below the process
- stratum. */
+ stratum.
+
+ Note that rather than allow an empty stack, we always have the
+ dummy target at the bottom stratum, so we can call the target
+ methods without checking them. */
#include "target/target.h"
#include "target/resume.h"
const char *name;
};
-/* Return a pretty printed form of TARGET_OPTIONS.
- Space for the result is malloc'd, caller must free. */
-extern char *target_options_to_string (int target_options);
+/* Return a pretty printed form of TARGET_OPTIONS. */
+extern std::string target_options_to_string (int target_options);
/* Possible types of events that the inferior handler will have to
deal with. */
of the process ID of the process in question, in hexadecimal
format. */
TARGET_OBJECT_EXEC_FILE,
+ /* FreeBSD virtual memory mappings. */
+ TARGET_OBJECT_FREEBSD_VMMAP,
+ /* FreeBSD process strings. */
+ TARGET_OBJECT_FREEBSD_PS_STRINGS,
/* Possible future objects: TARGET_OBJECT_FILE, ... */
};
struct target_ops
{
/* To the target under this one. */
- target_ops *m_beneath;
target_ops *beneath () const;
/* Free resources associated with the target. Note that singleton
TARGET_DEFAULT_RETURN (false);
virtual int have_steppable_watchpoint ()
TARGET_DEFAULT_RETURN (false);
- virtual bool have_continuable_watchpoint ()
- TARGET_DEFAULT_RETURN (false);
virtual bool stopped_data_address (CORE_ADDR *)
TARGET_DEFAULT_RETURN (false);
virtual bool watchpoint_addr_within_range (CORE_ADDR, CORE_ADDR, int)
NULL. */
extern target_ops *get_native_target ();
+/* Type that manages a target stack. See description of target stacks
+ and strata at the top of the file. */
+
+class target_stack
+{
+public:
+ target_stack () = default;
+ DISABLE_COPY_AND_ASSIGN (target_stack);
+
+ /* Push a new target into the stack of the existing target
+ accessors, possibly superseding some existing accessor. */
+ void push (target_ops *t);
+
+ /* Remove a target from the stack, wherever it may be. Return true
+ if it was removed, false otherwise. */
+ bool unpush (target_ops *t);
+
+ /* Returns true if T is pushed on the target stack. */
+ bool is_pushed (target_ops *t) const
+ { return at (t->to_stratum) == t; }
+
+ /* Return the target at STRATUM. */
+ target_ops *at (strata stratum) const { return m_stack[stratum]; }
+
+ /* Return the target at the top of the stack. */
+ target_ops *top () const { return at (m_top); }
+
+ /* Find the next target down the stack from the specified target. */
+ target_ops *find_beneath (const target_ops *t) const;
+
+private:
+ /* The stratum of the top target. */
+ enum strata m_top {};
+
+ /* The stack, represented as an array, with one slot per stratum.
+ If no target is pushed at some stratum, the corresponding slot is
+ null. */
+ target_ops *m_stack[(int) debug_stratum + 1] {};
+};
+
/* The ops structure for our "current" target process. This should
never be NULL. If there is no target, it points to the dummy_target. */
/* Return true if the target stack has a non-default
"terminal_ours" method. */
-extern int target_supports_terminal_ours (void);
+extern bool target_supports_terminal_ours (void);
/* Kill the inferior process. Make it go away. */
/* Hardware watchpoint interfaces. */
+/* GDB's current model is that there are three "kinds" of watchpoints,
+ with respect to when they trigger and how you can move past them.
+
+ Those are: continuable, steppable, and non-steppable.
+
+ Continuable watchpoints are like x86's -- those trigger after the
+ memory access's side effects are fully committed to memory. I.e.,
+ they trap with the PC pointing at the next instruction already.
+ Continuing past such a watchpoint is doable by just normally
+ continuing, hence the name.
+
+ Both steppable and non-steppable watchpoints trap before the memory
+ access. I.e, the PC points at the instruction that is accessing
+ the memory. So GDB needs to single-step once past the current
+ instruction in order to make the access effective and check whether
+ the instruction's side effects change the watched expression.
+
+ Now, in order to step past that instruction, depending on
+ architecture and target, you can have two situations:
+
+ - steppable watchpoints: you can single-step with the watchpoint
+ still armed, and the watchpoint won't trigger again.
+
+ - non-steppable watchpoints: if you try to single-step with the
+ watchpoint still armed, you'd trap the watchpoint again and the
+ thread wouldn't make any progress. So GDB needs to temporarily
+ remove the watchpoint in order to step past it.
+
+ If your target/architecture does not signal that it has either
+ steppable or non-steppable watchpoints via either
+ target_have_steppable_watchpoint or
+ gdbarch_have_nonsteppable_watchpoint, GDB assumes continuable
+ watchpoints. */
+
/* Returns non-zero if we were stopped by a hardware watchpoint (memory read or
write). Only the INFERIOR_PTID task is being queried. */
#define target_have_steppable_watchpoint \
(current_top_target ()->have_steppable_watchpoint ())
-/* Non-zero if we have continuable watchpoints */
-
-#define target_have_continuable_watchpoint \
- (current_top_target ()->have_continuable_watchpoint ())
-
/* Provide defaults for hardware watchpoint functions. */
/* If the *_hw_beakpoint functions have not been defined