int main(int argc, char *argv[]) { char *filename = NULL; struct display_info disp; int ret; /* set defaults */ memset(&disp, '\0', sizeof(disp)); disp.flags = FDT_REG_SUPERNODES; /* Default flags */ scan_args(&disp, argc, argv); /* Show matched lines in colour if we can */ disp.colour = disp.all && isatty(0); /* Any additional arguments can match anything, just like -g */ while (optind < argc - 1) { if (value_add(&disp, &disp.value_head, FDT_IS_ANY, 1, argv[optind++])) usage("Cannot add value"); } if (optind < argc) filename = argv[optind++]; if (!filename) usage("Missing filename"); /* If a valid .dtb is required, set flags to ensure we get one */ if (disp.output == OUT_DTB) { disp.header = 1; disp.flags |= FDT_REG_ADD_MEM_RSVMAP | FDT_REG_ADD_STRING_TAB; } if (disp.output_fname) { disp.fout = fopen(disp.output_fname, "w"); if (!disp.fout) usage("Cannot open output file"); } else { disp.fout = stdout; } /* Run the grep and output the results */ ret = do_fdtgrep(&disp, filename); if (disp.output_fname) fclose(disp.fout); if (ret) return 1; return 0; }
void test_add(void) { SSlice s1; SSlice s2; Value v1; Value v2; Value v3; char *v1s; char *v2s; char *result; mpd_context_t mpd_ctx; mpd_maxcontext(&mpd_ctx); sslice_assign_validate(&s1, NUMBER1); sslice_assign_validate(&s2, NUMBER2); value_init_number(&v1, &mpd_ctx); value_init_number(&v2, &mpd_ctx); value_init_number(&v3, &mpd_ctx); value_set_number_from_sslice(&v1, &s1); value_set_number_from_sslice(&v2, &s2); value_add(&v3, &v1, &v2); value_as_string(&v1s, &v1); value_as_string(&v2s, &v2); value_as_string(&result, &v3); if (strcmp(result, NUMBER3) != 0) { die("Addition failed\n"); } free(v1s); free(v2s); free(result); }
/* Return a virtual function as a value. ARG1 is the object which provides the virtual function table pointer. *ARG1P is side-effected in calling this function. F is the list of member functions which contains the desired virtual function. J is an index into F which provides the desired virtual function. TYPE is the type in which F is located. */ static struct value * gnuv2_virtual_fn_field (struct value **arg1p, struct fn_field * f, int j, struct type * type, int offset) { struct value *arg1 = *arg1p; struct type *type1 = check_typedef (value_type (arg1)); struct type *entry_type; /* First, get the virtual function table pointer. That comes with a strange type, so cast it to type `pointer to long' (which should serve just fine as a function type). Then, index into the table, and convert final value to appropriate function type. */ struct value *entry; struct value *vfn; struct value *vtbl; struct value *vi = value_from_longest (builtin_type_int, (LONGEST) TYPE_FN_FIELD_VOFFSET (f, j)); struct type *fcontext = TYPE_FN_FIELD_FCONTEXT (f, j); struct type *context; if (fcontext == NULL) /* We don't have an fcontext (e.g. the program was compiled with g++ version 1). Try to get the vtbl from the TYPE_VPTR_BASETYPE. This won't work right for multiple inheritance, but at least we should do as well as GDB 3.x did. */ fcontext = TYPE_VPTR_BASETYPE (type); context = lookup_pointer_type (fcontext); /* Now context is a pointer to the basetype containing the vtbl. */ if (TYPE_TARGET_TYPE (context) != type1) { struct value *tmp = value_cast (context, value_addr (arg1)); arg1 = value_ind (tmp); type1 = check_typedef (value_type (arg1)); } context = type1; /* Now context is the basetype containing the vtbl. */ /* This type may have been defined before its virtual function table was. If so, fill in the virtual function table entry for the type now. */ if (TYPE_VPTR_FIELDNO (context) < 0) fill_in_vptr_fieldno (context); /* The virtual function table is now an array of structures which have the form { int16 offset, delta; void *pfn; }. */ vtbl = value_primitive_field (arg1, 0, TYPE_VPTR_FIELDNO (context), TYPE_VPTR_BASETYPE (context)); /* With older versions of g++, the vtbl field pointed to an array of structures. Nowadays it points directly to the structure. */ if (TYPE_CODE (value_type (vtbl)) == TYPE_CODE_PTR && TYPE_CODE (TYPE_TARGET_TYPE (value_type (vtbl))) == TYPE_CODE_ARRAY) { /* Handle the case where the vtbl field points to an array of structures. */ vtbl = value_ind (vtbl); /* Index into the virtual function table. This is hard-coded because looking up a field is not cheap, and it may be important to save time, e.g. if the user has set a conditional breakpoint calling a virtual function. */ entry = value_subscript (vtbl, vi); } else { /* Handle the case where the vtbl field points directly to a structure. */ vtbl = value_add (vtbl, vi); entry = value_ind (vtbl); } entry_type = check_typedef (value_type (entry)); if (TYPE_CODE (entry_type) == TYPE_CODE_STRUCT) { /* Move the `this' pointer according to the virtual function table. */ set_value_offset (arg1, value_offset (arg1) + value_as_long (value_field (entry, 0))); if (!value_lazy (arg1)) { set_value_lazy (arg1, 1); value_fetch_lazy (arg1); } vfn = value_field (entry, 2); } else if (TYPE_CODE (entry_type) == TYPE_CODE_PTR) vfn = entry; else error (_("I'm confused: virtual function table has bad type")); /* Reinstantiate the function pointer with the correct type. */ deprecated_set_value_type (vfn, lookup_pointer_type (TYPE_FN_FIELD_TYPE (f, j))); *arg1p = arg1; return vfn; }
static void scan_args(struct display_info *disp, int argc, char *argv[]) { int opt; while ((opt = util_getopt_long()) != EOF) { int type = 0; int inc = 1; switch (opt) { case_USAGE_COMMON_FLAGS case 'a': disp->show_addr = 1; break; case 'A': disp->all = 1; break; case 'b': type = FDT_NODE_HAS_PROP; break; case 'C': inc = 0; /* no break */ case 'c': type = FDT_IS_COMPAT; break; case 'd': disp->diff = 1; break; case 'e': disp->flags |= FDT_REG_DIRECT_SUBNODES; break; case 'f': disp->show_offset = 1; break; case 'G': inc = 0; /* no break */ case 'g': type = FDT_ANY_GLOBAL; break; case 'H': disp->header = 1; break; case 'l': disp->region_list = 1; break; case 'L': disp->list_strings = 1; break; case 'm': disp->flags |= FDT_REG_ADD_MEM_RSVMAP; break; case 'N': inc = 0; /* no break */ case 'n': type = FDT_IS_NODE; break; case 'o': disp->output_fname = optarg; break; case 'O': if (!strcmp(optarg, "dtb")) disp->output = OUT_DTB; else if (!strcmp(optarg, "dts")) disp->output = OUT_DTS; else if (!strcmp(optarg, "bin")) disp->output = OUT_BIN; else usage("Unknown output format"); break; case 'P': inc = 0; /* no break */ case 'p': type = FDT_IS_PROP; break; case 'r': disp->remove_strings = 1; break; case 'R': disp->include_root = 1; break; case 's': disp->flags |= FDT_REG_ALL_SUBNODES; break; case 'S': disp->flags &= ~FDT_REG_SUPERNODES; break; case 't': disp->flags |= FDT_REG_ADD_STRING_TAB; break; case 'T': disp->add_aliases = 1; break; case 'v': disp->invert = 1; break; case 'I': disp->show_dts_version = 1; break; } if (type && value_add(disp, &disp->value_head, type, inc, optarg)) usage("Cannot add value"); } if (disp->invert && disp->types_exc) usage("-v has no meaning when used with 'exclude' conditions"); }
int slap_send_search_reference( Operation *op, SlapReply *rs ) { BerElementBuffer berbuf; BerElement *ber = (BerElement *) &berbuf; int rc = 0; int bytes; char *edn = rs->sr_entry ? rs->sr_entry->e_name.bv_val : "(null)"; AttributeDescription *ad_ref = slap_schema.si_ad_ref; AttributeDescription *ad_entry = slap_schema.si_ad_entry; rs->sr_type = REP_SEARCHREF; if ( op->o_callback ) { rc = slap_response_play( op, rs ); if ( rc != SLAP_CB_CONTINUE ) { goto rel; } } Debug( LDAP_DEBUG_TRACE, "=> send_search_reference: dn=\"%s\"\n", edn ); if ( rs->sr_entry && ! access_allowed( op, rs->sr_entry, ad_entry, NULL, ACL_READ, NULL ) ) { Debug( LDAP_DEBUG_ACL, "send_search_reference: access to entry not allowed\n" ); rc = 1; goto rel; } if ( rs->sr_entry && ! access_allowed( op, rs->sr_entry, ad_ref, NULL, ACL_READ, NULL ) ) { Debug( LDAP_DEBUG_ACL, "send_search_reference: access " "to reference not allowed\n" ); rc = 1; goto rel; } if( op->o_domain_scope ) { Debug( LDAP_DEBUG_ANY, "send_search_reference: domainScope control in (%s)\n", edn ); rc = 0; goto rel; } if( rs->sr_ref == NULL ) { Debug( LDAP_DEBUG_ANY, "send_search_reference: null ref in (%s)\n", edn ); rc = 1; goto rel; } if( op->o_protocol < LDAP_VERSION3 ) { rc = 0; /* save the references for the result */ if( rs->sr_ref[0].bv_val != NULL ) { if( value_add( &rs->sr_v2ref, rs->sr_ref ) ) rc = LDAP_OTHER; } goto rel; } #ifdef LDAP_CONNECTIONLESS if( op->o_conn && op->o_conn->c_is_udp ) { ber = op->o_res_ber; } else #endif { ber_init_w_nullc( ber, LBER_USE_DER ); ber_set_option( ber, LBER_OPT_BER_MEMCTX, &op->o_tmpmemctx ); } rc = ber_printf( ber, "{it{W}" /*"}"*/ , op->o_msgid, LDAP_RES_SEARCH_REFERENCE, rs->sr_ref ); if( rc != -1 ) { rc = send_ldap_controls( op, ber, rs->sr_ctrls ); } if( rc != -1 ) { rc = ber_printf( ber, /*"{"*/ "N}" ); } if ( rc == -1 ) { Debug( LDAP_DEBUG_ANY, "send_search_reference: ber_printf failed\n" ); #ifdef LDAP_CONNECTIONLESS if (!op->o_conn || op->o_conn->c_is_udp == 0) #endif ber_free_buf( ber ); set_ldap_error( rs, LDAP_OTHER, "encode DN error" ); goto rel; } rc = 0; rs_flush_entry( op, rs, NULL ); #ifdef LDAP_CONNECTIONLESS if (!op->o_conn || op->o_conn->c_is_udp == 0) { #endif bytes = send_ldap_ber( op, ber ); ber_free_buf( ber ); if ( bytes < 0 ) { rc = LDAP_UNAVAILABLE; } else { ldap_pvt_thread_mutex_lock( &op->o_counters->sc_mutex ); ldap_pvt_mp_add_ulong( op->o_counters->sc_bytes, (unsigned long)bytes ); ldap_pvt_mp_add_ulong( op->o_counters->sc_refs, 1 ); ldap_pvt_mp_add_ulong( op->o_counters->sc_pdu, 1 ); ldap_pvt_thread_mutex_unlock( &op->o_counters->sc_mutex ); } #ifdef LDAP_CONNECTIONLESS } #endif if ( rs->sr_ref != NULL ) { int r; for ( r = 0; !BER_BVISNULL( &rs->sr_ref[ r ] ); r++ ) { Statslog( LDAP_DEBUG_STATS2, "%s REF #%d \"%s\"\n", op->o_log_prefix, r, rs->sr_ref[0].bv_val ); } } else { Statslog( LDAP_DEBUG_STATS2, "%s REF \"(null)\"\n", op->o_log_prefix ); } Debug( LDAP_DEBUG_TRACE, "<= send_search_reference\n" ); if ( 0 ) { rel: rs_flush_entry( op, rs, NULL ); } if ( op->o_callback ) { (void)slap_cleanup_play( op, rs ); } if ( rs->sr_flags & REP_CTRLS_MUSTBEFREED ) { rs->sr_flags ^= REP_CTRLS_MUSTBEFREED; /* paranoia */ if ( rs->sr_ctrls ) { slap_free_ctrls( op, rs->sr_ctrls ); rs->sr_ctrls = NULL; } } return rc; }