All of lore.kernel.org
 help / color / mirror / Atom feed
From: Sven Schnelle <svens@stackframe.org>
To: "Alex Bennée" <alex.bennee@linaro.org>,
	"Alexandre Iooss" <erdnaxe@crans.org>,
	"Mahmoud Mandour" <ma.mandourr@gmail.com>,
	"Pierrick Bouvier" <pierrick.bouvier@linaro.org>
Cc: qemu-devel@nongnu.org, deller@gmx.de,
	Sven Schnelle <svens@stackframe.org>
Subject: [PATCH v3 01/12] util/log: convert debug_regions to GList
Date: Fri,  1 Mar 2024 18:45:58 +0100	[thread overview]
Message-ID: <20240301174609.1964379-2-svens@stackframe.org> (raw)
In-Reply-To: <20240301174609.1964379-1-svens@stackframe.org>

In preparation of making the parsing part of qemu_set_dfilter_ranges()
available to other users, convert it to return a GList, so the result
can be used with other functions taking a GList of struct Range.

Signed-off-by: Sven Schnelle <svens@stackframe.org>
---
 util/log.c | 36 ++++++++++++++++++------------------
 1 file changed, 18 insertions(+), 18 deletions(-)

diff --git a/util/log.c b/util/log.c
index d36c98da0b..779c0689a9 100644
--- a/util/log.c
+++ b/util/log.c
@@ -46,7 +46,7 @@ static __thread Notifier qemu_log_thread_cleanup_notifier;
 
 int qemu_loglevel;
 static bool log_per_thread;
-static GArray *debug_regions;
+static GList *debug_regions;
 
 /* Returns true if qemu_log() will really write somewhere. */
 bool qemu_log_enabled(void)
@@ -368,38 +368,36 @@ bool qemu_set_log_filename_flags(const char *name, int flags, Error **errp)
  */
 bool qemu_log_in_addr_range(uint64_t addr)
 {
-    if (debug_regions) {
-        int i = 0;
-        for (i = 0; i < debug_regions->len; i++) {
-            Range *range = &g_array_index(debug_regions, Range, i);
-            if (range_contains(range, addr)) {
-                return true;
-            }
-        }
-        return false;
-    } else {
+    GList *p;
+
+    if (!debug_regions) {
         return true;
     }
-}
 
+    for (p = g_list_first(debug_regions); p; p = g_list_next(p)) {
+        if (range_contains(p->data, addr)) {
+            return true;
+        }
+    }
+    return false;
+}
 
 void qemu_set_dfilter_ranges(const char *filter_spec, Error **errp)
 {
     gchar **ranges = g_strsplit(filter_spec, ",", 0);
+    struct Range *range = NULL;
     int i;
 
     if (debug_regions) {
-        g_array_unref(debug_regions);
+        g_list_free_full(debug_regions, g_free);
         debug_regions = NULL;
     }
 
-    debug_regions = g_array_sized_new(FALSE, FALSE,
-                                      sizeof(Range), g_strv_length(ranges));
     for (i = 0; ranges[i]; i++) {
         const char *r = ranges[i];
         const char *range_op, *r2, *e;
         uint64_t r1val, r2val, lob, upb;
-        struct Range range;
+        range = g_new0(struct Range, 1);
 
         range_op = strstr(r, "-");
         r2 = range_op ? range_op + 1 : NULL;
@@ -448,10 +446,12 @@ void qemu_set_dfilter_ranges(const char *filter_spec, Error **errp)
             error_setg(errp, "Invalid range");
             goto out;
         }
-        range_set_bounds(&range, lob, upb);
-        g_array_append_val(debug_regions, range);
+        range_set_bounds(range, lob, upb);
+        debug_regions = g_list_append(debug_regions, range);
+        range = NULL;
     }
 out:
+    g_free(range);
     g_strfreev(ranges);
 }
 
-- 
2.43.2



  reply	other threads:[~2024-03-01 17:47 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-01 17:45 [PATCH v3 00/12] plugins/execlog: add data address match and address range support Sven Schnelle
2024-03-01 17:45 ` Sven Schnelle [this message]
2024-03-04 10:34   ` [PATCH v3 01/12] util/log: convert debug_regions to GList Alex Bennée
2024-03-04 13:13     ` Sven Schnelle
2024-03-04 17:00       ` Richard Henderson
2024-03-04 16:59     ` Sven Schnelle
2024-03-04 17:58       ` Alex Bennée
2024-03-04 19:12         ` Sven Schnelle
2024-03-01 17:45 ` [PATCH v3 02/12] util/log: make qemu_set_dfilter_ranges() take a GList Sven Schnelle
2024-03-01 17:46 ` [PATCH v3 03/12] util/range: move range_list_from_string() to range.c Sven Schnelle
2024-03-01 17:46 ` [PATCH v3 04/12] util/range: add range_list_free() Sven Schnelle
2024-03-01 17:46 ` [PATCH v3 05/12] util/range: use append_new_range() in range_list_from_string() Sven Schnelle
2024-03-01 17:46 ` [PATCH v3 06/12] util/range: split up range_list_from_string() Sven Schnelle
2024-03-01 17:46 ` [PATCH v3 07/12] util/range: make range_list_from_string() accept a single number Sven Schnelle
2024-03-01 17:46 ` [PATCH v3 08/12] qemu/range: add range_list_contains() function Sven Schnelle
2024-03-01 17:46 ` [PATCH v3 09/12] plugins: add API to print errors Sven Schnelle
2024-03-01 17:46 ` [PATCH v3 10/12] plugins: add range list API Sven Schnelle
2024-03-03 17:45   ` Bernhard Beschow
2024-03-01 17:46 ` [PATCH v3 11/12] plugins/execlog: use range list api Sven Schnelle
2024-03-01 17:46 ` [PATCH v3 12/12] plugins/execlog: add data address match Sven Schnelle

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240301174609.1964379-2-svens@stackframe.org \
    --to=svens@stackframe.org \
    --cc=alex.bennee@linaro.org \
    --cc=deller@gmx.de \
    --cc=erdnaxe@crans.org \
    --cc=ma.mandourr@gmail.com \
    --cc=pierrick.bouvier@linaro.org \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.