aboutsummaryrefslogtreecommitdiff
path: root/gdb/user-selection.h
diff options
context:
space:
mode:
authorSimon Marchi <simon.marchi@ericsson.com>2016-12-08 13:06:14 -0500
committerSimon Marchi <simon.marchi@ericsson.com>2017-02-23 17:25:30 -0500
commit44c04ee9bf959b40819de6327500557fbb5d8c4a (patch)
treef2fae0b73585f6b67cfbb0f7c29d65f9d70ebc77 /gdb/user-selection.h
parenta567769b813b2538bebc97d689fc0739f172028e (diff)
downloadbinutils-users/simark/user-selection-rfc.zip
binutils-users/simark/user-selection-rfc.tar.gz
binutils-users/simark/user-selection-rfc.tar.bz2
Decouple user selection from internal selectionusers/simark/user-selection-rfc
I am sending this as an RFC because it's far from complete and definitive, but I'd like to gather some comments and opinions before going further in this direction. The goal of this patch is to decouple the notion of the user-selected inferior/thread/frame from GDB's internally selected inferior/thread/frame. Currently, for example, the inferior_ptid variable has two jobs: - it's the user-selected thread: it's changed by the "thread" command. Other commands (continue, backtrace, etc) apply to this thread. - it's the internally-selected thread: it defines the thread GDB is currently "working" on. For example, implementations of to_xfer_partial will refer to it to know from which thread to read/write memory. Because of this dual usage, if we want to do some operations on a thread other than the currently selected one, we have to save the current inferior/thread/frame and restore them when we're done. Failing to do so would result in an unexpected selection switch for the user. To improve this, Pedro suggested in [1] to decouple the two concepts. This is essentially what this patch is trying to do. A new "user_selection" object is introduced, which contains the selected inferior/thread/frame from the point of view of the user. Before every command, we "apply" this selection to the core of GDB to make sure the internal selection matches the user selection. There is a single user selection for the whole GDB (named "global user-selection"), but as was mentioned in the linked thread, it opens the door to having different selections for different UIs. This means that each UI would have its own user-selection object, which would be applied to the core prior to executing commands from this UI. The global user-selection object only gets modified when we really intend to change it. It can be because of the thread / -thread-select / up / down / frame / inferior commands, a breakpoint hit in all-stop, an inferior exit, etc. The problem that initially prompted this effort is that the "--thread" flag of MI commands changes the user-selected thread under the user's feet. My initial attempt to fix it was to restore the selection after the MI command execution. However, some cases are hard to get right. For example: (thread 1 is currently selected) -interpreter-exec --thread 2 console "thread 3" Restoring the selected thread to thread 1 after the MI command execution wrongfully cancels the switch to thread 3. So it's hard to determine when we should or shouldn't restore. With the current patch, it works naturally: the --thread flag doesn't touch the user-selected thread, only the internal one. The "thread 3" command updates the user selection. Another difficulty is to send the right notifications to MI when the user selection changes. That means to not miss any, but not send too many either. Getting it somewhat right lead to ugly hacks (see the command_notifies_uscc_observer function) and even then it's not perfect (see the kfails in user-selected-context-sync.exp test). With the proposed method, it's easy to know when the user-selection changes and send notifications. With this patch, there are probably a few usage of make_cleanup_restore_current_thread that are not needed anymore, if they are only used to restore the user selection. I kept removing them for a later time though. In the current state, there are a few minor regressions in the testsuite (especially some follow-fork stuff I'm not sure how to handle), but the vast majority of the previously passing tests still pass. Comments are welcome! Thanks, Simon [1] https://sourceware.org/ml/gdb-patches/2016-08/msg00031.html
Diffstat (limited to 'gdb/user-selection.h')
-rw-r--r--gdb/user-selection.h100
1 files changed, 100 insertions, 0 deletions
diff --git a/gdb/user-selection.h b/gdb/user-selection.h
new file mode 100644
index 0000000..a6f9af3
--- /dev/null
+++ b/gdb/user-selection.h
@@ -0,0 +1,100 @@
+#ifndef USER_SELECTION_H
+#define USER_SELECTION_H
+
+class user_selection {
+public:
+
+ /* Default constructor, nothing is selected. */
+
+ user_selection ()
+ : m_inferior (nullptr),
+ m_thread (nullptr),
+ m_frame_id (null_frame_id),
+ m_frame_level (INVALID_FRAME_LEVEL)
+ {}
+
+ /* Make INF the selected inferior. If NOTIFY is true, call the observer
+ indicating a selection change.
+
+ Return true if the newly selected inferior is different than the previously
+ selected inferior. */
+
+ bool select_inferior (struct inferior *inf, bool notify);
+
+ /* Make THREAD the selected thread. If NOTIFY is true, call the observer
+ indicating a selection change.
+
+ Return true if the newly selected thread is different than the previously
+ selected thread. */
+
+ bool select_thread (struct thread_info *thread, bool notify);
+
+ /* Make FRAME the selected frame. If NOTIFY is true, call the observer
+ indicating a selection change.
+
+ Return true if the newly selected frame is different than the previously
+ selected frame. */
+
+ bool select_frame (struct frame_info *frame, bool notify);
+
+ /* Get the selected inferior. */
+
+ struct inferior *inferior () const
+ { return m_inferior; }
+
+ /* Get the selected thread. */
+
+ struct thread_info *thread () const
+ { return m_thread; }
+
+ /* Get the selected frame. */
+
+ struct frame_info *
+ frame ()
+ {
+ if (!has_valid_frame ())
+ try_select_current_frame ();
+
+ if (!has_valid_frame ())
+ return NULL;
+
+ return frame_find_by_id (m_frame_id);
+ }
+
+ frame_id
+ raw_frame_id () const
+ { return m_frame_id; }
+
+ int
+ raw_frame_level () const
+ { return m_frame_level; }
+
+ bool has_valid_frame () const
+ { return m_frame_level != INVALID_FRAME_LEVEL; }
+
+private:
+
+ struct inferior *m_inferior;
+ struct thread_info *m_thread;
+
+ struct frame_id m_frame_id;
+ int m_frame_level;
+
+ void sanity_check () const;
+ void try_select_current_frame ();
+};
+
+/* Get the global user selection. */
+
+user_selection *global_user_selection ();
+
+/* Initialize the global user selection. This must be called after the initial
+ inferior has been created. */
+
+void init_global_user_selection ();
+
+/* Apply the global user selection to core of gdb. */
+
+void apply_global_user_selection ();
+
+#endif /* USER_SELECTION_H */