TestFunctionLookup.java revision 178476
1141240Snjl/* 2167905Snjl * CDDL HEADER START 3141240Snjl * 4141240Snjl * The contents of this file are subject to the terms of the 5141240Snjl * Common Development and Distribution License (the "License"). 6141240Snjl * You may not use this file except in compliance with the License. 7141240Snjl * 8141240Snjl * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9141240Snjl * or http://www.opensolaris.org/os/licensing. 10141240Snjl * See the License for the specific language governing permissions 11141240Snjl * and limitations under the License. 12141240Snjl * 13141240Snjl * When distributing Covered Code, include this CDDL HEADER in each 14141240Snjl * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15141240Snjl * If applicable, add the following below this CDDL HEADER, with the 16141240Snjl * fields enclosed by brackets "[]" replaced with your own identifying 17141240Snjl * information: Portions Copyright [yyyy] [name of copyright owner] 18141240Snjl * 19141240Snjl * CDDL HEADER END 20141240Snjl */ 21141240Snjl 22141240Snjl/* 23141240Snjl * Copyright 2006 Sun Microsystems, Inc. All rights reserved. 24141240Snjl * Use is subject to license terms. 25141240Snjl * 26141240Snjl * ident "%Z%%M% %I% %E% SMI" 27141240Snjl */ 28141240Snjl 29141240Snjlimport org.opensolaris.os.dtrace.*; 30141240Snjl 31141240Snjl/** 32141240Snjl * Regression for bug 6413280 lookupKernelFunction() and 33141240Snjl * lookupUserFunction() truncate last character. 34141240Snjl */ 35142603Snjlpublic class TestFunctionLookup { 36141240Snjl static final String kernelLookupProgram = "sdt:::callout-start { " + 37141240Snjl "@[((callout_t *)arg0)->c_func] = count(); }"; 38141240Snjl static final String userLookupProgram = "pid$target::f2:entry { " + 39141240Snjl "@[arg0] = count(); }"; 40173204Snjl 41141240Snjl public static void 42173204Snjl main(String[] args) 43141240Snjl { 44141240Snjl if (args.length != 1) { 45142603Snjl System.err.println("usage: java TestFunctionLookup <command>"); 46141814Snjl System.exit(1); 47167905Snjl } 48141240Snjl String cmd = args[0]; 49141240Snjl 50141240Snjl Consumer consumer = new LocalConsumer(); 51141240Snjl try { 52141240Snjl consumer.open(); 53141240Snjl consumer.compile(kernelLookupProgram); 54141240Snjl consumer.enable(); 55141240Snjl consumer.go(); 56141240Snjl Aggregate a; 57141240Snjl Number address; 58142395Snjl String f; 59141240Snjl boolean done = false; 60142395Snjl for (int i = 0; (i < 20) && !done; ++i) { 61141240Snjl Thread.currentThread().sleep(100); 62150847Sume a = consumer.getAggregate(); 63150847Sume for (Aggregation agg : a.getAggregations()) { 64150847Sume for (Tuple tuple : agg.asMap().keySet()) { 65150847Sume address = (Number)tuple.get(0).getValue(); 66150847Sume if (address instanceof Integer) { 67150847Sume int addr = (Integer)address; 68141240Snjl f = consumer.lookupKernelFunction(addr); 69142603Snjl } else { 70141240Snjl long addr = (Long)address; 71141923Snjl f = consumer.lookupKernelFunction(addr); 72150847Sume } 73141923Snjl if (f.equals("genunix`setrun")) { 74141413Snjl System.out.println(f); 75141945Snjl done = true; 76141240Snjl } 77141240Snjl } 78167905Snjl } 79210422Savg } 80141240Snjl consumer.close(); 81141240Snjl } catch (Exception e) { 82141240Snjl e.printStackTrace(); 83141240Snjl System.exit(1); 84141240Snjl } 85141240Snjl 86141240Snjl consumer = new LocalConsumer(); 87141240Snjl try { 88141240Snjl consumer.open(); 89141240Snjl int pid = consumer.createProcess(cmd); 90142603Snjl consumer.compile(userLookupProgram); 91142603Snjl consumer.enable(); 92142603Snjl consumer.go(); 93142603Snjl Thread.currentThread().sleep(500); 94142603Snjl Aggregate a = consumer.getAggregate(); 95144876Snjl Number address; 96144876Snjl String f; 97144876Snjl for (Aggregation agg : a.getAggregations()) { 98144876Snjl for (Tuple tuple : agg.asMap().keySet()) { 99144876Snjl address = (Number)tuple.get(0).getValue(); 100141240Snjl if (address instanceof Integer) { 101167905Snjl int addr = (Integer)address; 102141240Snjl f = consumer.lookupUserFunction(pid, addr); 103141240Snjl } else { 104141240Snjl long addr = (Long)address; 105141240Snjl f = consumer.lookupUserFunction(pid, addr); 106141240Snjl } 107141240Snjl System.out.println(f); 108141413Snjl } 109141240Snjl } 110141413Snjl consumer.close(); 111141413Snjl } catch (Exception e) { 112141413Snjl e.printStackTrace(); 113141413Snjl System.exit(1); 114141240Snjl } 115141240Snjl } 116142114Snjl} 117141240Snjl