Stackdb
Stackdb is a stackable, multi-target and -level source debugger and memory forensics library.
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
target_event.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2014 The University of Utah
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License as
6  * published by the Free Software Foundation; either version 2 of
7  * the License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
17  */
18 
19 #include <stdlib.h>
20 
21 #include "log.h"
22 #include "target_event.h"
23 #include "target_api.h"
24 #include "target.h"
25 
27  struct target_thread *thread,
28  target_event_t type,void *priv) {
29  struct target_event *retval = calloc(1,sizeof(*retval));
30 
31  retval->type = type;
32  retval->target = target;
33  if (target)
34  retval->id = target->id;
35  else
36  retval->id = -1;
37  if (thread)
38  retval->tid = thread->tid;
39  else
40  retval->tid = -1;
41  retval->thread= thread;
42  retval->priv = priv;
43 
44  return retval;
45 }
46 
48  struct target_thread *thread,
50  void *priv,void *priv2) {
51  struct target_event *retval = target_create_event(target,thread,type,priv);
52  retval->priv2 = priv2;
53  return retval;
54 }
55 
56 void target_broadcast_event(struct target *target,struct target_event *event) {
57  struct target *overlay;
58 
60  "event %s from target %s broadcasting on target %s\n",
61  TARGET_EVENT_NAME(event->type),event->target->name,target->name);
62 
63  /* Tell the given target, if it's different. */
64  if (target != event->target) {
65  if (target->ops->handle_event)
66  target->ops->handle_event(target,event);
67  }
68 
69  /* Bubble down... */
70  if (target->base) {
72  "event %s from target %s broadcasting to base target %s\n",
73  TARGET_EVENT_NAME(event->type),event->target->name,
74  target->base->name);
75  if (target->base->ops->handle_event)
76  target->base->ops->handle_event(target->base,event);
77  }
78 
79  /* And bubble up... */
80  if (event->thread) {
81  overlay = target_lookup_overlay(target,event->thread->tid);
82  if (overlay) {
84  "event %s from target %s broadcasting to overlay target %s\n",
85  TARGET_EVENT_NAME(event->type),event->target->name,
86  overlay->name);
87  if (overlay->ops->handle_event)
88  overlay->ops->handle_event(overlay,event);
89  }
90  }
91 
92  free(event);
93 }
target_event_t
Definition: target_event.h:28
struct target * base
Definition: target_api.h:2654
void target_broadcast_event(struct target *target, struct target_event *event)
Definition: target_event.c:56
struct target_event * target_create_event_2(struct target *target, struct target_thread *thread, target_event_t type, void *priv, void *priv2)
Definition: target_event.c:47
struct target * target
Definition: target_event.h:198
void free(void *ptr)
Definition: debugserver.c:207
void(* handle_event)(struct target *target, struct target_event *event)
Definition: target_api.h:2902
#define vdebug(devel, areas, flags, format,...)
Definition: log.h:302
void * calloc(size_t nmemb, size_t size)
Definition: debugserver.c:200
Definition: log.h:70
struct target_thread * thread
Definition: target_event.h:199
char * name
Definition: target_api.h:2521
struct target * target_lookup_overlay(struct target *target, tid_t tid)
Definition: target.c:4497
struct target_ops * ops
Definition: target_api.h:2548
Definition: log.h:162
target_event_t type
Definition: target_event.h:190
int id
Definition: target_api.h:2514
struct target_event * target_create_event(struct target *target, struct target_thread *thread, target_event_t type, void *priv)
Definition: target_event.c:26