int main(int argc, char** argv) { enum { SHOW_USAGE, SETCAPSLOCK_ON, SETCAPSLOCK_OFF, SETCAPSLOCK_TOGGLE, GETCAPSLOCK }; int mod = LockMask; // see <X11/X.h> int action = SHOW_USAGE; char* cmd; if (argc == 3) { mod = 1<<atoi(argv[2]); } if (argc >= 2) { cmd = argv[1]; if (strcasecmp(cmd, "on") == 0) { action = SETCAPSLOCK_ON; } else if (strcasecmp(cmd, "off") == 0) { action = SETCAPSLOCK_OFF; } else if (strcasecmp(cmd, "toggle") == 0) { action = GETCAPSLOCK; } else if (strcasecmp(cmd, "get") == 0) { action = GETCAPSLOCK; } } if (action == SHOW_USAGE) { usage(argv[0]); return 1; } if (action == SETCAPSLOCK_ON) { set_modifier(mod, 1); } if (action == SETCAPSLOCK_OFF) { set_modifier(mod, 0); } if (action == SETCAPSLOCK_TOGGLE) { set_modifier(mod, !get_modifier(mod)); } if (action == GETCAPSLOCK) { printf("%s\n", get_modifier(mod) ? "on" : "off"); } return 0; }
void VMEvent::clear_event_request(VMEvent *ep) { LocationModifier::Raw mod; Thread::Raw thread; VMEvent::remove_event_request(ep); #ifdef AZZERT if (TraceDebugger) { tty->print_cr("VMEvent: clear 0x%x, id 0x%x", (int)ep->obj(), ep->event_id()); } #endif switch (ep->event_kind()) { case JDWP_EventKind_BREAKPOINT: mod = get_modifier(ep, JDWP_EventRequest_Set_Out_modifiers_Modifier_LocationOnly); GUARANTEE(!mod.is_null(), "No location modifier for breakpoint event"); if (!mod.is_null()) { #if ENABLE_ISOLATES // See if any other task already has a breakpoint here. VMEvent::Raw epb = find_breakpoint_event(&mod); if (!epb.is_null()) { // Has to be some other task since we have unlinked this event GUARANTEE(epb().task_id() != ep->task_id(), "Duplicate breakpoint event for this task"); } else { #endif mod().set_method_opcode(mod().save_opcode(), false); #if ENABLE_ISOLATES } #endif } break; case JDWP_EventKind_SINGLE_STEP: mod = get_modifier(ep, JDWP_EventRequest_Set_Out_modifiers_Modifier_Step); if (mod.not_null()) { thread = JavaDebugger::get_thread_by_id(mod().thread_id()); if (thread.not_null()) thread().set_is_stepping(false); JavaDebugger::set_stepping(false); } break; } // see if there are any other breakpoints in this method. If no other // breakpoints and the compiler is active then clear the // impossible_to_compile flag. if (mod.not_null() && (ep->event_kind() == JDWP_EventKind_BREAKPOINT || ep->event_kind() == JDWP_EventKind_SINGLE_STEP)) { clear_impossible_to_compile(&mod, ep); } }
Bytecodes::Code VMEvent::get_verifier_breakpoint_opcode(const Method* this_method, int bci) { UsingFastOops fast_oops; InstanceClass::Fast cl; // We may get called from Method::check_bytecodes() and the holder // hasn't been set yet. Check for 0xFFFF class id which is illegal if (this_method->holder_id() == 0xFFFF) { // No class has been set yet, just return the breakpoint opcode return Bytecodes::_breakpoint; } cl = this_method->holder(); /* point to class of method */ // We may get called during GC when stackmaps are generated and we are // iterating over bytecodes. So, we can't allocate. VMEvent::Raw ep = find_breakpoint_event(JavaDebugger::get_object_id_by_ref(&cl), JavaDebugger::get_method_id(this_method), (jlong)bci, -1); if (ep.is_null()) { return Bytecodes::_illegal; } LocationModifier::Raw location = get_modifier(&ep, JDWP_EventRequest_Set_Out_modifiers_Modifier_LocationOnly); GUARANTEE(!location.is_null(), "No location modifier for event"); return(location().save_opcode()); }
void pf_o(t_dt *data) { t_av av; int len; av.ui = get_modifier(data); av.s = ft_itoa_base(av.ui, 8); av.len = ft_strlen(av.s) + data->flag.hash; len = (data->flag.precision > av.len) ? data->flag.precision : av.len; print_zero_space(data, &av); if (*data->tail == 'o') { if (data->flag.hash || !data->flag.point || av.ui) write_str(data, av.s, av.len - data->flag.hash); } else if (!data->flag.point || *(data->flag.point + 1) != '0') write_str(data, av.s, av.len - data->flag.hash); if (data->flag.minus) { while (data->flag.min_width > len && data->flag.min_width--) write_char(data, ' '); } if (av.s) free(av.s); }
int Stats::get_modifier(Actor *owner, Stats::StatType stattype) { if (owner->stats) { int attribute = owner->stats->get_attribute(owner, stattype); return get_modifier(attribute); } else { return 0; }; };
int eff_skill_study(const unit * u, skill_t sk, const region * r) { int level = get_level(u, sk); if (level > 0) { int mlevel = level + get_modifier(u, sk, level, r, true); if (mlevel > 0) return mlevel; } return 0; }
static void get_data(t_dt *data, t_av *av, size_t *len, char **ptr) { av->ui = get_modifier(data, len); ft_itoa_base2(av->ui, 16, av->s); av->len = ft_strlen(av->s); *ptr = (av->len >= *len) ? &av->s[av->len - *len] : av->s; av->len = ft_strlen(*ptr); if (data->flag.point && av->ui == 0) av->len = 1; if (*data->tail == 'X') ft_strtoupper(*ptr); }
void Weave::ShowNew(const ROOM_INDEX_DATA & room) { for (CHAR_DATA * ch(room.people); ch != NULL; ch = ch->next_in_room) { // Check for skill if (number_percent() >= get_modifier(ch->affected, gsn_weavesense) && !is_an_avatar(ch)) continue; // Skill check passed check_improve(ch, NULL, gsn_weavesense, TRUE, 4); send_to_char("You sense the Weave twist and flex around you, its primal energy branching and flowing in new patterns!\n", ch); } }
int eff_skill(const unit * u, skill_t sk, const region * r) { if (skill_enabled[sk]) { int level = get_level(u, sk); if (level > 0) { int mlevel = level + get_modifier(u, sk, level, r, false); if (mlevel > 0) { int skillcap = SkillCap(sk); if (skillcap && mlevel > skillcap) { return skillcap; } return mlevel; } } } return 0; }
static bool strunit_to_uint64(char *str, uint64_t *value, const char **mod) { int i, mod_len; double val; char mod_str[20]; char num_str[50]; const int64_t mult[] = {1, /* byte */ 1024, /* kilobyte */ 1000, /* kb kilobyte */ 1048576, /* megabyte */ 1000000, /* mb megabyte */ 1073741824, /* gigabyte */ 1000000000}; /* gb gigabyte */ if (!get_modifier(str, num_str, sizeof(num_str), mod_str, sizeof(mod_str))) { return 0; } /* Now find the multiplier corresponding to the modifier */ mod_len = strlen(mod_str); if (mod_len == 0) { i = 0; /* default with no modifier = 1 */ } else { for (i=0; mod[i]; i++) { if (bstrncasecmp(mod_str, mod[i], mod_len)) { break; } } if (mod[i] == NULL) { return false; } } Dmsg2(900, "str=%s: mult=%d\n", str, mult[i]); errno = 0; val = strtod(num_str, NULL); if (errno != 0 || val < 0) { return false; } *value = (utime_t)(val * mult[i]); return true; }
void VMEvent::replace_event_opcode(Method *method, Bytecodes::Code bcode, int bci) { UsingFastOops fast_oops; InstanceClass::Fast clazz = method->holder(); // find this breakpoint VMEvent::Raw ep = find_breakpoint_event(JavaDebugger::get_object_id_by_ref(&clazz), JavaDebugger::get_method_id(method), (jlong)bci, -1); if (ep.is_null()) { // if we didn't find the breakpoint event, then just replace the bytecode method->bytecode_at_put_raw(bci, bcode); } else { // Set the saved opcode to the new fast opcode LocationModifier::Raw location = get_modifier(&ep, JDWP_EventRequest_Set_Out_modifiers_Modifier_LocationOnly); GUARANTEE(!location.is_null(), "No location modifier for event"); location().set_save_opcode(bcode); } return; }
ReturnOop VMEvent::find_breakpoint_event(int class_id, jlong method_id, jlong offset, int task_id) { // May be called during GC via GenerateStackMap::run(). VMEventStream es; VMEvent::Raw ep; LocationModifier::Raw loc; while (!es.at_end()) { ep = es.next_by_kind(JDWP_EventKind_BREAKPOINT); if (ep.is_null()) { return NULL; } #if ENABLE_ISOLATES // If task_id == -1 && ep.task_id == -1 then we don't care // which task this is we check the event otherwise we skip it if (task_id != -1 && ep().task_id() != -1 && (ep().task_id() != task_id)) { continue; } #else (void)task_id; #endif loc = get_modifier(&ep, JDWP_EventRequest_Set_Out_modifiers_Modifier_LocationOnly); if (loc.not_null()) { if (loc().clazz_id() == class_id && loc().method_id() == method_id && loc().offset() == offset) { return ep; } } } return (ReturnOop)NULL; }
void VMEvent::exception_event(Throwable *exception, JavaFrame *catch_frame, DebuggerEvent *d_event, int catch_offset) { check_notify_wanted(Dbg_EventKind_EXCEPTION); UsingFastOops fast_oops; VMEvent::Fast ep, ep_2; jlong throw_offset = 0; int event_count = 0; jbyte suspend_policy = JDWP_SuspendPolicy_NONE; InstanceClass::Fast ic; LocationModifier::Fast location; Method::Fast catch_method; Method::Fast throw_method; int data_len = JDWP_EVENT_LEN; ep = ep_2 = get_event_request(d_event, event_count, suspend_policy); if (ep.is_null()) { return; } // Flush any packets waiting in the queue. This helps avoid a race // condition where we may have a resume command in the queue for a // previous event, we send this event, process the resume command // out of order JavaDebugger::dispatch(0); // Calculate packet length data_len += (JDWP_EVENT_EXCEPTION_LEN * event_count); Transport::Fast transport = ep().transport(); PacketOutputStream out(&transport, data_len, JDWP_COMMAND_SET(Event), JDWP_COMMAND(Event, Composite)); // Create a buffered output stream so we can asynchronously send an error // Calculate the size based on half of the items being 'longs' UsingFastOops fast_oops_2; Thread::Fast thread = JavaDebugger::get_thread_by_id(d_event->thread_id()); VMEventModifier::deoptimize_frame(&thread, true); VMEvent::Fast info_event = find_event((jbyte)VM_EXCEPTION_INFO_EVENT); if (!info_event.is_null()) { location = get_modifier(&info_event, JDWP_EventRequest_Set_Out_modifiers_Modifier_LocationOnly); GUARANTEE(!location.is_null(), "No location modifier in info event"); throw_method = location().method(); throw_offset = location().offset(); remove_event_request(&info_event); } else { UsingFastOops fast_oops_3; ObjArray::Fast trace, methods; TypeArray::Fast offsets; trace = exception->backtrace(); if (!trace.is_null()) { methods = trace().obj_at(0); offsets = trace().obj_at(1); if (!methods.is_null() && !offsets.is_null()) { throw_method = methods().obj_at(0); throw_offset = (jlong)(offsets().int_at(0)); } } } DEBUGGER_EVENT(("Exception")); out.write_byte(suspend_policy); out.write_int(event_count); while (ep.not_null()) { out.write_byte(JDWP_EventKind_EXCEPTION); out.write_int(ep().event_id()); // thread with exception out.write_int(d_event->thread_id()); // location of exception throw if (throw_method.not_null()) { ic = throw_method().holder(); } DebuggerEvent throw_event(JDWP_EventKind_EXCEPTION, 0, // don't need thread JavaDebugger::get_object_id_by_ref(&ic), JavaDebugger::get_method_id(&ic, &throw_method), (jlong)throw_offset); throw_event.write_as_location(&out); // thrown exception out.write_byte('L'); out.write_object(exception); // location of catch, or 0 if not caught if (catch_frame == NULL) { LocationModifier::write_null_location(&out); } else { catch_method = catch_frame->method(); ic = catch_method().holder(); DebuggerEvent catch_event(JDWP_EventKind_EXCEPTION, 0, // don't need thread JavaDebugger::get_object_id_by_ref(&ic), JavaDebugger::get_method_id(&ic, &catch_method), (jlong)catch_offset); catch_event.write_as_location(&out); } ep = ep().send_next(); } out.send_packet(); JavaDebugger::process_suspend_policy(suspend_policy, &thread, true); }
/* * Convert a string duration to utime_t (64 bit seconds) * Returns false: if error true: if OK, and value stored in value */ bool duration_to_utime(char *str, utime_t *value) { int i, mod_len; double val, total = 0.0; char mod_str[20]; char num_str[50]; /* * The "n" = mins and months appears before minutes so that m maps to months. */ static const char *mod[] = { "n", "seconds", "months", "minutes", "mins", "hours", "days", "weeks", "quarters", "years", (char *)NULL }; static const int32_t mult[] = { 60, 1, 60 * 60 * 24 * 30, 60, 60, 3600, 3600 * 24, 3600 * 24 * 7, 3600 * 24 * 91, 3600 * 24 * 365, 0 }; while (*str) { if (!get_modifier(str, num_str, sizeof(num_str), mod_str, sizeof(mod_str))) { return false; } /* Now find the multiplier corresponding to the modifier */ mod_len = strlen(mod_str); if (mod_len == 0) { i = 1; /* default to seconds */ } else { for (i=0; mod[i]; i++) { if (bstrncasecmp(mod_str, mod[i], mod_len)) { break; } } if (mod[i] == NULL) { return false; } } Dmsg2(900, "str=%s: mult=%d\n", num_str, mult[i]); errno = 0; val = strtod(num_str, NULL); if (errno != 0 || val < 0) { return false; } total += val * mult[i]; } *value = (utime_t)total; return true; }
void VMEvent::create_event_request(PacketInputStream *in, PacketOutputStream *out, jbyte event_kind) { UsingFastOops fast_oops; VMEvent::Fast ep; int i; bool error = false; VMEventModifier::Fast current_modifier_slot, new_modifier, event_modifier; ep = create_vm_event_request(); ep().set_event_kind(event_kind); ep().set_suspend_policy(in->read_byte()); ep().set_num_modifiers(in->read_int()); Transport *transport = in->transport(); ep().set_transport(transport); #if ENABLE_ISOLATES ep().set_task_id(transport->task_id()); TaskGCContext tmp(transport->task_id()); #endif for (i=0; i < ep().num_modifiers(); i++) { new_modifier = VMEventModifier::new_modifier(in, out, error); if (error) { // some sort of error happened if (out->error() != 0) { out->send_packet(); } return; } if (new_modifier.is_null()) { // Most likely we don't support this modifier continue; } if (event_kind == JDWP_EventKind_BREAKPOINT && new_modifier().mod_kind() == JDWP_EventRequest_Set_Out_modifiers_Modifier_LocationOnly) { UsingFastOops fastoops2; LocationModifier *lmp = (LocationModifier *)&new_modifier; VMEvent::Fast epb = VMEvent::find_breakpoint_event(lmp, transport->task_id()); if (epb.not_null()) { out->write_int(epb().event_id()); out->send_packet(); // out->send_error(JDWP_Error_NOT_IMPLEMENTED); // there's a breakpoint here already, don't bother installing another return; } #if ENABLE_ISOLATES InstanceClass::Raw ic = JavaDebugger::get_object_by_id(new_modifier().clazz_id()); if (ic().class_id() < ROM::number_of_system_classes()) { // breakpoint in system class, allow in any task ep().set_task_id(-1); } // See if any other task already has a breakpoint here. epb = find_breakpoint_event(lmp); if (!epb.is_null()) { // Has to be some other task since we haven't linked in this event GUARANTEE(epb().task_id() != transport->task_id(), "Breakpoint already inserted"); LocationModifier::Raw lmod = get_modifier(&epb, JDWP_EventRequest_Set_Out_modifiers_Modifier_LocationOnly); GUARANTEE(!lmod.is_null(),"Breakpoint event has no location modifier"); lmp->set_save_opcode(lmod().save_opcode()); } else { #endif /* Return an error back to the debugger if * the breakpoint could not be installed. */ lmp->unlink_method(); lmp->save_method_entry(); if (lmp->set_method_opcode(Bytecodes::_breakpoint, true) == false){ out->send_error(JDWP_Error_INVALID_LOCATION); return; } #if ENABLE_ISOLATES } #endif } // insert the mod at the end of the list of modifiers event_modifier = ep().mods(); if (event_modifier.is_null()) { ep().set_mods(&new_modifier); current_modifier_slot = ep().mods(); } else { current_modifier_slot().set_next(&new_modifier); current_modifier_slot = new_modifier; } } #ifdef AZZERT if (TraceDebugger) { tty->print_cr("Create Event: xprt = 0x%x, ep = 0x%lx, id = 0x%x, kind = 0x%lx, suspend = 0x%lx, num mods = 0x%lx", transport->obj(), ep.obj(), ep().event_id(), ep().event_kind(), ep().suspend_policy(), ep().num_modifiers()); } #endif ep().set_next((VMEvent *)Universe::vmevent_request_head()); *Universe::vmevent_request_head() = ep; out->write_int(ep().event_id()); out->send_packet(); VMEvent::add_notification(JDWP_eventkind_to_dbg_eventkind(event_kind)); }
void VMEvent::clear_impossible_to_compile(LocationModifier *mod, VMEvent *ep) { UsingFastOops fast_oops; // If we are using the compiler then we should reset the // impossible_to_compile flag for this method (and potentially one frame // up if it's a single step). // We also check the previous state of the method, if it was // "impossible_to_compile" we don't reset the flag. InstanceClass::Fast clazz; Method::Fast method, callerMethod; LocationModifier::Fast thisMod; Method::Fast m = mod->method(); // if (!m().has_compiled_code()) { // if method does not have compiled code then just return // return; // } if (m.is_null()) { // Method was removed. Most likely it was a <clinit> method return; } VMEvent::Fast epm; VMEventStream es; bool found_one = false; while (!es.at_end()) { epm = es.next(); if ((epm().event_kind() == JDWP_EventKind_BREAKPOINT || epm().event_kind() == JDWP_EventKind_SINGLE_STEP) && (ep == NULL || !epm.equals(ep))) { thisMod = get_modifier(&epm, JDWP_EventRequest_Set_Out_modifiers_Modifier_LocationOnly); if (thisMod.not_null()) { method = thisMod().method(); if (method.equals(&m)) { // another breakpoint in this method, keep impossible_to_compile set found_one = true; break; } } } } if (!found_one) { // we must have looped through the whole list and not found another // breakpoint in this method so clear the impossible_to_compile flag if (mod->rom_debug_method() != NULL) { // This method is in ROM, let's check all method pointers on the java // stack to see if any of them point to this rom_debug_method. // We may be called as a result of JVM::cleanup(). Thread doesn't have // a stack in that case. Thread *thread = Thread::current(); if (thread->last_java_fp() != NULL && thread->last_java_sp() != NULL) { Frame fr(Thread::current()); while (true) { if (fr.is_entry_frame()) { EntryFrame e = fr.as_EntryFrame(); if (e.is_first_frame()) { break; } e.caller_is(fr); } else if (fr.is_java_frame()) { JavaFrame jf = fr.as_JavaFrame(); if (jf.method() == mod->rom_debug_method()) { MethodDesc *md = (MethodDesc *)mod->method(); // fix up the stored bcp in this frame int bci = jf.bci_with_flags(); jf.set_raw_method(md); Method::Raw m = jf.method(); jf.set_raw_bcp((address)(bci + m().code_base())); } jf.caller_is(fr); } } } } // We also check the previous state of the method, if it was // "impossible_to_compile" we don't reset the flag. if (mod->compile_state() == true) { // Method was compilable so set entry to default m().set_default_entry(false); } else { if (ep->event_kind() == JDWP_EventKind_BREAKPOINT) { // May have been a special native method like String.charAt. // Just replace the entry with what we had saved earlier GUARANTEE(!ObjectHeap::contains((OopDesc*)mod->saved_method_entry()), "ROM method entry is in heap"); m().variable_part()->set_execution_entry(mod->saved_method_entry()); } } } }
void Weave::ShowWeave(CHAR_DATA & ch, const ROOM_INDEX_DATA & room) { // Check for skill bool hasGraven(is_affected(&ch, gsn_gravenmind)); bool gravenOnly(false); if (number_percent() > get_modifier(ch.affected, gsn_weavesense) && !is_an_avatar(&ch)) { if (hasGraven) gravenOnly = true; else return; } // Check for sundered weave if (area_is_affected(room.area, gsn_sunderweave)) return; // Check for a fount check_improve(&ch, NULL, gsn_weavesense, TRUE, 4); std::ostringstream mess; mess << std::hex; bool anyWeave(false); if (room.ley_group != NULL) { if (room.ley_group->HasFount() && (!gravenOnly || room.ley_group->FountOrderPower() > 0)) { anyWeave = true; long attunedID(room.ley_group->AttunedID()); if (attunedID != LeyGroup::Unattuned) mess << ((attunedID == ch.id) ? "[{WResonant{x] " : "[{WDissonant{x] "); if (gravenOnly) mess << "A sense of deep, humming power fills this place, marking it as a nexus of order."; else { // Note that founts don't get modified by normal ley modifiers mess << GenerateFountDescription(room.ley_group->FountOrderPower(), room.ley_group->FountPositivePower(), AdjacentLeyRooms(room, &room)); if (IS_IMMORTAL((&ch))) mess << " {c[ID: " << reinterpret_cast<unsigned long>(&room) << "]{x"; } mess << "\n"; } // Check for ley lines if (!gravenOnly) { for (unsigned int i(0); i < room.ley_group->LineCount(); ++i) { anyWeave = true; const LeyInfo & leyLine(room.ley_group->Line(i)); mess << GenerateLineDescription(ApplyOrderModifiers(leyLine.OrderPower, room), ApplyPositiveModifiers(leyLine.PositivePower, room), AdjacentLeyRooms(room, leyLine.ID)); if (IS_IMMORTAL((&ch))) mess << " {c[ID: " << reinterpret_cast<unsigned long>(leyLine.ID) << "]{x"; mess << "\n"; } } } if (hasGraven) { // Graven mind can sense order founts in adjacent rooms for (unsigned int i(0); i < Direction::Max; ++i) { Direction::Value direction(static_cast<Direction::Value>(i)); ROOM_INDEX_DATA * nextRoom(Direction::Adjacent(room, direction)); if (nextRoom != NULL && nextRoom->ley_group != NULL && nextRoom->ley_group->HasFount() && nextRoom->ley_group->FountOrderPower() > 0) { anyWeave = true; mess << "The deep, steady thrum of an order nexus resonates " << Direction::SourceNameFor(direction) << ".\n"; } } } if (anyWeave) { mess << "\n"; send_to_char(mess.str().c_str(), &ch); } }